Tutorial by Examples

string fullOrRelativePath = "testfile.txt"; string fileData; using (var reader = new StreamReader(fullOrRelativePath)) { fileData = reader.ReadToEnd(); } Note that this StreamReader constructor overload does some auto encoding detection, which may or may not conform to the ...
First, let's see three different ways of extracting data from a file. string fileText = File.ReadAllText(file); string[] fileLines = File.ReadAllLines(file); byte[] fileBytes = File.ReadAllBytes(file); On the first line, we read all the data in the file as a string. On the second line, we r...
Iterating over connected serial ports using System.IO.Ports; string[] ports = SerialPort.GetPortNames(); for (int i = 0; i < ports.Length; i++) { Console.WriteLine(ports[i]); } Instantiating a System.IO.SerialPort object using System.IO.Ports; SerialPort port = new SerialPort(); ...

Page 1 of 1