Nytro Posted August 17, 2011 Report Posted August 17, 2011 Foarte multe exemple pentru diferite actiuni.Exemple:using System;public class HelloWorld{ public static void Main(string[] args) { Console.Write("Hello World!"); }}using System;namespace PlayingAround { class ReadAll { public static void Main(string[] args) { string contents = System.IO.File.ReadAllText(@"C:\t1"); Console.Out.WriteLine("contents = " + contents); } }}public static string getFileAsString(string fileName) { StreamReader sReader = null; string contents = null; try { FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); sReader = new StreamReader(fileStream); contents = sReader.ReadToEnd(); } finally { if(sReader != null) { sReader.Close(); } } return contents;}using System;namespace PlayingAround { class ReadAll { public static void Main(string[] args) { string[] lines = System.IO.File.ReadAllLines(@"C:\t1"); Console.Out.WriteLine("contents = " + lines.Length); Console.In.ReadLine(); } }}StreamReader sr = new StreamReader("fileName.txt");string line;while((line= sr.ReadLine()) != null) { Console.WriteLine("xml template:"+line);}if (sr != null)sr.Close(); //should be in a "finally" or "using" blockusing System;namespace PlayingAround { class ReadAll { public static void Main(string[] args) { string myText = "Line1" + Environment.NewLine + "Line2" + Environment.NewLine; System.IO.File.WriteAllText(@"C:\t2", myText); } }}using System;using System.IO;public class WriteFileStuff {public static void Main() { FileStream fs = new FileStream("c:\\tmp\\WriteFileStuff.txt", FileMode.OpenOrCreate, FileAccess.Write); StreamWriter sw = new StreamWriter(fs); try { sw.WriteLine("Howdy World."); } finally { if(sw != null) { sw.Close(); } }}}In fine, sunt foarte multe cu sintaxa evidentiata (syntax highlight, pe romaneste):http://www.fincher.org/tips/Languages/csharp.shtml Quote