C#笔记(二)——输入输出函数

一:输入函数:

1:

string a = Console.ReadLine(); 将输入的字符串放入变量a中;

2:

 int a = Console.Read(); 将输入的字符串的第一个字符的ASC码存入整形变量a中;

二:换行(在下一行执行):       Console.WriteLine();

 输入: int a = 9;
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine(a);

三:格式化输出

  a: 输入:

     int a = 1;int b = 2;int c = 3;
            Console.WriteLine("a={0},b={1},c={2}",a,b,c);

      输出:

           

  b:输入:

            float score = 23.5f;
            //f表示小数点后保留几位,后面可以加数字
            Console.WriteLine("score={0:F2}", score);
            Console.WriteLine("score={0:0.000}", score);

      输出:


   c:输入

            //把数据转换成%形式,并保留两个小数位
            Console .WriteLine("{0:p2}" , 1 / 4f);
            //如果字符串前面加@,则字符串里面的转义字符失效
            Console .Write(@"lanoukeji " );
            Console .Write("hello world" );
 


          

原文地址:https://www.cnblogs.com/ningyongbin/p/5922028.html