Click here to Skip to main content
15,895,872 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is my code !!

C#
FileStream fs = new FileStream(@"C:\movies\call.txt",FileMode.Truncate,FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
Console.WriteLine("Enter the string :");
sw.Write(Console.Read());

:- When i type "1234" in the console, it gives me the output in the "call.txt" file in the integer format because i use Read() method here but i do not know what the read() method is returning, in this case "49".

thanks !!!!
Posted
Updated 16-Nov-13 20:21pm
v2
Comments
Sampath Lokuge 17-Nov-13 2:23am    
Check this may be helped to you.http://www.dotnetperls.com/console-readline

1 solution

If you aren't sure what a method does, the first thing to do is turn to Google: "Console.read"[^]
This normally finds the MSDN at the top of the list: MSDN: "Console.Read Method"[^] which generally explains it pretty well.

In this case, Console.Read returns a single character the user typed: '1' in an integer - which has the value 49 in decimal. Your write method (when handed an integer) writes that integer as a string to the file: "49".
Perhaps you want to consider using Console.ReadLine instead? That would return "1234" as a string instead.
 
Share this answer
 
Comments
Anupsssss 17-Nov-13 3:43am    
Thanks a lot it helps .
OriginalGriff 17-Nov-13 3:48am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900