C#基础知识

 

 

  1. 输出
Console.WriteLine("123");

 

 

字符串 String

 

  1. 字符串插入变量
    string aFriend = "Scott";
    Console.WriteLine($"Hello{aFriend}");

     

  2. 变量的长度
    Console.WriteLine($"Hello{aFriend.Length}");

     

  3. 字符串的空白
    string greeting = "        Hello World     " ;
    
    string trimmedGreeting=greeting.TrimStart();
    
    trimmedGreeting=greeting.TrimEnd();
    
    trimmedGreeting=greeting.Trim();

     

  4. 字符串替换
    string sayHello = "Hekki World";
    Console.WriteLine(sayHello);
    
    sayHello=sayHello.Replace("Hello","Greetings");
    Console.WriteLine(sayHello);

     

  5. 字符串字母变大变小
    string sayHello = "Hekki World";
    Console.WriteLine(sayHello.ToUpper());
    Console.WriteLine(sayHello.ToLower());

     

  6. 字符串是否包含这些字符
    string songLyrics = "You say goodbye,and I say hello";
    
    Console.WriteLine(songLyrics.Contains("goodbye"));
    Console.WriteLine(songLyrics.Contains("greetings"));

    输出true或false

 

 

 

Number

  1. 加减乘除
    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);
    
    
    ................

     

  2. Integer 的精准最大和最小
    int max=int.MaxValue;
    int min=int.MinValue;

    double max=double .MaxValue;
    double min=double .MinValue;

     

  3. 小数  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

 

 

var names = new List<string>{"<name>"};

 

 

数组的   Sort();       IndexOf();

 

 

 

 

 

 

posted @ 2023-02-03 15:07  漫漫长路</>  阅读(10)  评论(0编辑  收藏  举报