本文介绍了System.IO中的Read()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码!!
Here is my code !!
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());: - 当我在控制台中输入1234时,它给出了 call.txt整数格式的文件,因为我在这里使用了Read()方法,但我不知道read()方法返回什么,在本例中为49。 谢谢!!!!
:- 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 !!!!
推荐答案如果您不确定方法的作用,首先要做的是转向Google:Console.read [ ^ ] 这通常会找到MSDN位于列表顶部: MSDN:Console.Read方法 [ ^ ]这一般说得很清楚。 在这种情况下,Console.Read返回用户输入的单个字符:整数中的1 - 其值为十进制值49。您的写入方法(当递给整数时)将该整数作为字符串写入文件:49。 也许您想考虑使用Console.ReadLine?这将返回1234作为字符串。 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.
更多推荐
System.IO中的Read()方法
发布评论