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 @   漫漫长路</>  阅读(19)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性
· 2025年我用 Compose 写了一个 Todo App
点击右上角即可分享
微信分享提示