How to permanently save input given by user in c# console application?

前端 未结 2 1390
走了就别回头了
走了就别回头了 2021-01-26 06:36

I am creating an application that takes input from user and save it permanently in form of table.

    Console.Write(\"\\n\\tEnter roll no\\n\\t\");  
    v= Conv         


        
相关标签:
2条回答
  • 2021-01-26 07:05

    First you have to create an string array with your data then you can write it to the txt file

    string[] lines = { "First line", "Second line", "Third line" };
    

    WriteAllLines creates a file, writes a collection of strings to the file,and then closes the file.

    System.IO.File.WriteAllLines(@"C:\Users\Public\TestFolder\WriteLines.txt",lines);
    

    How to: Write to a Text File (C# Programming Guide)

    0 讨论(0)
  • 2021-01-26 07:11

    Refer to System.IO.File

    And this may be a quick help:

    using System;
    public class Test
    {
        public static void Main()
        {
            String Str = "";
    
            for(int i =0;i<10;i++)
            {
                Str += i.ToString();
            }
            Console.WriteLine(Str);
            System.IO.File.WriteAllText(@"C:\SaveInfo.Txt",Str);
        }
    }
    
    0 讨论(0)
提交回复
热议问题