Oktatás * Programozás 2 * Szkriptnyelvek * levelezősök Félévek Linkek * kalendárium |
CSharp /
20180506aReading a text file line by lineOption 1 using static System.Console; using System.IO; namespace cs { class Program { private const string INPUT = "pelda.txt"; public static void Main(string[] args) { string line; var f = new StreamReader(INPUT); while((line = f.ReadLine()) != null) // line doesn't contain '\n' at the end! { WriteLine(line); } f.Close(); } } } Option 2 using static System.Console; using System.IO; namespace cs { class Program { private const string INPUT = "pelda.txt"; public static void Main(string[] args) { using (var f = new StreamReader(INPUT)) { string line; while((line = f.ReadLine()) != null) { WriteLine(line); } } } } } This is similar to Python's |
Blogjaim, hobbi projektjeim * The Ubuntu Incident [ edit ] |