C#基础知识字符串

字符串

在字符串中转义字符\不起作用,要想显示"需要用""来表示。

            Console.WriteLine("没有@符号\\\t\t\\");
            Console.WriteLine(@"有@符号\\\t\t\\");
            Console.WriteLine("没有@符号\t\t\\");
            Console.WriteLine(@"有@符号\t\t\");
            string str = @"这是一个字符串用 "" 来表示 "" 号 ";
            Console.WriteLine(str);

打印结果

没 有 @符 号 \              \
有 @符 号 \\\t\t\\
没 有 @符 号                \
有 @符 号 \t\t\
这 是 一 个 字 符 串 用  " 来 表 示  " 号  

输入

string input =  Console.ReadLine();
Console.WriteLine("输入的字符串:" + input);
int intInput = Convert.ToInt32(input);//字符串转换成整数
Console.WriteLine("输入的数字:" + intInput);

字符串格式化输出

int a = 10, b = 30;
Console.WriteLine("{0}+{1}={2}", a, b, a + b);
10+30=40

自增表达式,放在前面变量后面先取变量再自增,放在变量前面先对变量自增再取值

int a = 5;
Console.WriteLine(a++);
Console.WriteLine(++a);
int b = a++;
Console.WriteLine("b=" + b + " a="+ a);
b = ++a;
Console.WriteLine("b=" + b + " a=" + a);
5
7
b=7 a=8
b=9 a=9
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容