0

The problem is I can't figure How to write console output to file. I want to save the results in a txt file I have been trying to look this up and I couldn't figure out how it works. I'm really stupid and I need some help I'd appreciate any help thanks in advance

using System;
using System.Drawing;
using System.Security.Cryptography;
using System.Text;

namespace ConsoleApp1
{
    internal class Program
    {
        public static string GetUniqueUSG(int maxSize)
        {
            char[] array = new char[62];
            array = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
            byte[] array2 = new byte[1];
            RNGCryptoServiceProvider rngcryptoServiceProvider = new RNGCryptoServiceProvider();
            rngcryptoServiceProvider.GetNonZeroBytes(array2);
            array2 = new byte[maxSize];
            rngcryptoServiceProvider.GetNonZeroBytes(array2);
            StringBuilder stringBuilder = new StringBuilder(maxSize);
            foreach (byte b in array2)
            {
                stringBuilder.Append(array[(int)b % array.Length]);
            }
            return stringBuilder.ToString();
        }

        public static string GetUniqueUSG2(int maxSize)
        {
            char[] array = new char[62];
            array = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_".ToCharArray();
            byte[] array2 = new byte[1];
            RNGCryptoServiceProvider rngcryptoServiceProvider = new RNGCryptoServiceProvider();
            rngcryptoServiceProvider.GetNonZeroBytes(array2);
            array2 = new byte[maxSize];
            rngcryptoServiceProvider.GetNonZeroBytes(array2);
            StringBuilder stringBuilder = new StringBuilder(maxSize);
            foreach (byte b in array2)
            {
                stringBuilder.Append(array[(int)b % array.Length]);
            }
            return stringBuilder.ToString();
        }

        private static void Main(string[] args)
        {
            for (int i = 0; i < 21247483647; i++)
            {
                Console.Write(string.Concat(new string[]
                {
                    "N",
                    Program.GetUniqueUSG(24),
                    ".X",
                    Program.GetUniqueUSG2(5),
                    ".",
                    Program.GetUniqueUSG2(27),
                    "\n"
                }), Color.Blue, Color.Fuchsia, 14);
                Console.Title = "By Theo Bagwell";
            }
            Console.ReadKey();
        }
    }
}
anastaciu
  • 23,467
  • 7
  • 28
  • 53
  • 1
    Does this answer your question? [How to Save Console.WriteLine Output to Text File](https://stackoverflow.com/questions/4470700/how-to-save-console-writeline-output-to-text-file) – devNull Aug 25 '20 at 00:44
  • well as i said im new to this stuff i've looked in that , and it's so confusing for me – BagwellIG Aug 25 '20 at 00:49
  • All you really need to do is create a `StreamWriter` and pass it to `Console.SetOut()`. You can directly copy the code from the answer I linked and then simply replace the file name with what you need. IMO, that seems relatively simple compared to the rest of your program. – devNull Aug 25 '20 at 00:53

0 Answers0