C#常用语法

  1. 判断 

    1.  if语句
    2. if....else 语句
    3. 嵌套 if语句
    4. switch 语句
    5. 嵌套switch语句
    6. ? : 运算符
  2. 循环

    1.  while循环
    2. for /foreach
      1. 这里简单介绍foreach 
        using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Text;
        
        namespace StudentCShrap
        {
            class MainClassTest
            {
                static void Main(string[] args)
                {
                    int[] TempArrar = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
                    foreach (int elem in TempArrar) //遍历数组: 数据类型 int 临时存储当前数据的变量 elem 关键字 in 数组名
                    {
                        Console.Write(" {0}", elem);
                    }
                    Console.WriteLine();
        
                    Console.ReadKey();
                    
                }
            }
        }
        
        
    3. do ... while
    4. 嵌套循环: 在一个循环里面控制更多的循环
    5. 循环控制语句: break 推出循环语句 , continue 跳出当前循环执行主体
  3.  
发布了24 篇原创文章 · 获赞 5 · 访问量 3208

猜你喜欢

转载自blog.csdn.net/Ellis1993/article/details/105309337