本代码演示了C#最简单的从控制台读取数据然后输出的例子
C#控制的输入输出主要由一下几个函数
Read : Reads a single character – int i = Console.Read(); ReadLline : 读取一行 – string str = Console.ReadLine(); Write : 输出一行 – Console.Write (“Write: 1″); WriteLine : 输出一行加上换行符(\n) – Console.WriteLine(“Test Output Data with Line”);
下面的详细范例
using System; namespace Consoleapp { class Classs1 { static void Main(string[ ] args ) { Console.Write("c# I/O Sample"); Console.WriteLine(""); Console.WriteLine ("= = = = = = = = "); Console.WriteLine ("Enter your age . . ."); string age = Console.ReadLine(); Console.WriteLine("Output: Your age is : "+ age); } } }
显示结果如下
= = = = = = = = Enter your age . . . 18 Output: Your age is : 18
附件:源代码下载