C#基础知识
- 输出
Console.WriteLine("123");
字符串 String
- 字符串插入变量
string aFriend = "Scott"; Console.WriteLine($"Hello{aFriend}");
- 变量的长度
Console.WriteLine($"Hello{aFriend.Length}");
- 字符串的空白
string greeting = " Hello World " ; string trimmedGreeting=greeting.TrimStart(); trimmedGreeting=greeting.TrimEnd(); trimmedGreeting=greeting.Trim();
- 字符串替换
string sayHello = "Hekki World"; Console.WriteLine(sayHello); sayHello=sayHello.Replace("Hello","Greetings"); Console.WriteLine(sayHello);
- 字符串字母变大变小
string sayHello = "Hekki World"; Console.WriteLine(sayHello.ToUpper()); Console.WriteLine(sayHello.ToLower());
- 字符串是否包含这些字符
string songLyrics = "You say goodbye,and I say hello"; Console.WriteLine(songLyrics.Contains("goodbye")); Console.WriteLine(songLyrics.Contains("greetings"));
输出true或false
Number
- 加减乘除
int a=18; int b=6; int c=a+b; Console.WriteLine(c); int a=18; int b=6; int c=a*b; Console.WriteLine(c); int a=18; int b=6; int c=a/b; Console.WriteLine(c); int a=18; int b=6; int c=2; int d=(a+b)*c; Console.WriteLine(d); ................
- Integer 的精准最大和最小
int max=int.MaxValue; int min=int.MinValue;
double max=double .MaxValue;
double min=double .MinValue; - 小数 decimals
double a=1.0; double b=3.0; Console.WriteLine(a / b); decimal c=1.0M; decimal d=3.0M; Console.WriteLine(c/d); long min=long.MinValue; long max=long.MaxValue; short min1=short .MinValue; short max1=short .MaxValue;
判断 循环
if
while
do while
for
foreach
Arrays, List, and Collections
var names = new List<string>{"<name>"};
Sort, Search, and Index Lists
数组的 Sort(); IndexOf();
Lists of Other Types

浙公网安备 33010602011771号