Posts

Showing posts from October, 2021

How to Copy array to List and Back in C#? -- C# -- Type Conversion

 How to Copy array to List and Back in C#? -- C# -- Type Conversion  array to List using ToList method [e.g.] list1=arr1.ToList<float>(); List to array  using CopyTo method list1.CopyTo(arr1); [NOTE] ToList() method is under System.Linq Don't forget to use using directive. using System.Linq;

How to Read from a Text File in C#? -- C# -- System.IO.StreamReader

 How to Read from a Text File in C#? -- C# -- System.IO.StreamReader  [Ans] using System.IO.StreamReader() [Syntax]  StreamReader StreamReader(string fileName); where fileName is the name of file that you read [NOTE] Great Importance!!! Please pay a lot attention!!! (1) Compiler reads file under subfiolder of the path \bin\Debug\netcoreapp3.1 in your project. When you use StreamReader, the argument will be given as  <yourProject>\bin\Debug\netcoreapp3.1\<fileName> e.g. When I create a new C# project with project name StreamReader_All in the path C:\Users\jayw7\OneDrive\桌面\CSharp\StreamReader . I should write  C:\Users\jayw7\OneDrive\桌面\CSharp\StreamReader\StreamReader_All\StreamReader_All\bin\Debug\netcoreapp3.1 (2) In C#, "\" means escape character. If you would like to present a directory, you must use "\\" instead of "\" or  add "@" before your directory. How to read all lines from text file in C#? step1: read file from text file w...