hi I am just starting out with c#. i am curious and confused about the difference of Read and Read Line in c# and what differ in their use? I hope you can help me guys.
Read gets the next character and converts it into ASCII code and return an int
//Entering a(lowercase) will print 97 as per the ASCII table int i = Console.Read(); Console.WriteLine(i); Console.ReadKey();
//Entering a here will return a since the int is converted to a char again int i = Console.Read(); char ch = Convert.ToChar(i); Console.WriteLine(ch); Console.ReadKey();
ReadLine just gets everything before enter key is pressed as a string
Note: Read() is almost never used, you almost certainly should use ReadLine and convert to int if you need to.