美文网首页
C#基础知识字符串

C#基础知识字符串

作者: 我就是那只小菜鸡 | 来源:发表于2022-10-12 15:38 被阅读0次

字符串

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

            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

相关文章

  • c#集合

    C#基础知识简单梳理

  • C#字符串比较方法

    C#字符串比较方法 用C#比较字符串有多种方法,如: string.Compare(x,y); string.Eq...

  • Allen Kashiwa的游戏开发信息

    1 基础知识与通用技能 1.1 语言相关 1.1.1 C/C++ C++ Primer 1.1.2 C# C# 编...

  • Unity 学习,C#基础学习

    包含,C#字符串,枚举,集合,数组以及类,属性的设置 C#基本数据类型代码一:字符串!using UnityEng...

  • 判断为空

    C# 字符串为空 数组为空

  • C# DateTime 和MySQL DateTime互相转换

    C# DateTime转成MySQL DateTime的字符串: MySQL 读出的DateTime转换成C#的D...

  • C#基础知识字符串

    字符串 在字符串中转义字符\不起作用,要想显示"需要用""来表示。 打印结果 输入 字符串格式化输出 自增表达式,...

  • c++传递字符串给c#使用问题

    C++里,字符串要占用内存的。C++创建字符串,并传给C#,就会造成内存泄露(因为C#不知道C++如何创建,也就不...

  • C#中转义字符

    C#中转义字符分2中,一种是\,一种是@。 @符号在C#中有两个作用 作用1、在字符串的前面加@表示取消字符串中的...

  • C#字符&&字符串相关操作

    1、C#中的字符串:分为正则字符串和原义字符串 正则字符串:以前用的,可以识别转义字符的原义字符串:@打头,“。。...

网友评论

      本文标题:C#基础知识字符串

      本文链接:https://www.haomeiwen.com/subject/mlutzrtx.html