System.IO中的Read()方法

编程入门 行业动态 更新时间:2024-10-25 03:19:18
本文介绍了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()方法

本文发布于:2023-11-09 22:54:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573654.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方法   System   IO   Read

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!