c#--On those little knowledge

foreword

  There are many small knowledge points in c#, but they still play a very important role in examples. Let's learn about "small knowledge" today!

Escapes\

\+特殊符号:显示特殊符号
\n:换行
\b:退格
\\\
\t:水平制表符
\":一个双引号
@:用在涉及到路径的时候用,加在最前面,会使\失

Placeholder

  1. Numbers, starting from 0 and increasing sequentially

string name="老牛"
Console.WriteLine("姓名:{0}",name);

  2. Use placeholders to keep valid numbers

int num1=10;
int num2=3;

double remainder=num1*1.0/num2;
Console.WriteLine("{0:0.00}",remainder;

convert

  1. Automatic type conversion : int can be automatically converted to double data, but there will be more decimals;

  2. Implicit conversion : The operand and result types involved in the operation must be the same. When inconsistent, an implicit conversion can occur if two conditions are met: the two types are compatible and the target type is greater than the source type; one operand in the expression is double, and the entire expression can be promoted to double.

  3. Display conversion : The two types must be compatible; if the data of double type is converted to data of int type, the precision will be lost.

double num1=303.6;
int num=(int)num1; //显示转换或者说是强制类型转换

  4. Type conversion : convent

  5. Three ways to convert strings into numbers

  console.writeline("输入数字");
  string strNum=console.readLine();

1.int age=Convert.Toint32(strNum);

2.int age =int.Parse(strNum);

3.int age=0;
  bool result = int.TryParse(strNum,out age);

two-value exchange

num3=num1;
num1=num2;
num2=num3;
num1=num1+num2;
num2=num1-num2;
num1=num1-num2;

+ sign connection

  If there is a string on both sides of the +, then the + acts as a connection.

Console.WriteLine("你好"+name)

Summarize

  Seeing this, have you mastered these "little knowledge"? If you have any suggestions or comments, please comment!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325492518&siteId=291194637