VS常用快捷键

p10--VS快捷键

 

 

Shift+End:光标定位到代码后面

Shift+Home:光标定位到代码前面

 

p11--字符类型 -- 变量类型

1.int : 整数

2.double : 整数/小数(小数点后15--16位)

3.金钱:decimal ----值后加m

4.string : 字符串

5.chart :单个字符

6.bool :

 

p17--占位符

1.先挖坑,再填坑

int a = 0;
int b = 0;
int c = 0;

Console.WriteLine("a{0},b{1},c{2}",a,b,c);

 

p19--接收用户的输入 Console.ReadLine();

Console.WriteLine("请输入");
string temp = Console.ReadLine();
Console.WriteLine("输入为:",temp);

 

p21--转义符  ‘\’+ 字符

 

 

 

p27--类型转换
1.自动  小 ---> 大      int——double

2.强制   大----> 小        double-----int

3.Convent 类型转换,实际是调用Parse  (转换失败,抛异常)

4.Parse 效率比Convent高一些   (转换失败,抛异常)

int.Parse("123");
double.Parse("123");
decimal.Parse("123");

5.TryParse();

int num = 0;
bool b = int.TryParse("123c",out num);//(参数==输入的数,返回值===结果)

 

p39 -- switch()

switch (level)
{
   case "A": salary += 500;
        break;
    case "B": salary += 200;
        break;
    case "C": break;
    case "D": salary -= 200;
        break;
    case "E": salary -= 500;
        break;
    default: 
        Console.WriteLine("输入有误,程序退出");
        b = false;
        break;
}

 

p40--while

while (true) //死循环
{

}

 

p42--break
1.跳出switch()的case循环
2.跳出while()循环 跳出当前循环


p45-- do--while  
1.先执行,再判断,while成立则再次执行,否则退出
2.至少执行一次

3.例如:小兰  彩排  彩排的好  回家  彩排的不好,,再次彩排

 

 

 p48 -- continue

//1.continue 跳出本次循环,判断while,为true,则循环,否则退出
//求1-100能被7整除的数
int i = 1;
int num = 0;
while (i <= 100)
{
    if (i % 7 == 0)
    {
        this.richTextBox1.AppendText(i + "\r\n");
        i++;
        continue;
    }
    num += i;
    i++;
}

 

p58 -- 调试

1.F10 逐过程调试

2.F11 单步调试

3.监视:调试--窗口--监视--监视1--添加监视值

 

 

 

 p60 -- 三元表达式

 

 

//三元表达式 凡是if--else都可用三元表达式

int n1 = 1;
int
n2 = 2;
int max = n1 > n2 ? n1 : n2;//如果n1 > n2 ,max = n1 ,否则 max = n2
//等同于
if (n1 > n2) { max = n1; } else { max = n2; }

 

p61 --  //产生随机数的方法

//1.创建能够产生随机数的对象
Random random = new Random();
//2.让产生随机数的对象调用方法来产生随机数(1-10) 左闭右开
int randomNumber = random.Next(1,11);

 

p63 -- 运算符

 

 

 

  -- 随机数

//1.创建能够产生随机数的对象
Random random = new Random();
//2.让产生随机数的对象调用方法来产生随机数(1-10)  左闭右开
int randomNumber = random.Next(1,11);

 

 p64 -- 常量 //常量 const

const int max;
const int max1 = 10;

 

p65 -- 枚举

 

 

 

p67 --  结构 : 一次性声明多个  不同类型  的变量

 

 

 

p68 -- 数组:一次性声明多个  相同类型  的变量

//类型 数组名 = new 数组类型[数组长度];  4种声明方式
int[] shuzu1 = new int[10];
int[] shuzu2 = {1,2,3 };
int[] shuzu3 = new int[3]{ 1, 2, 3 };
int[] shuzu4 = new int[]{1,2,3};

 

p71 -- 冒泡排序

int[] nums = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
for (int i = 0; i < nums.Length -1; i++)
{
    for (int j = 0; j < nums.Length - 1 - i; j++)
    {
        if (nums[j] > nums[j + 1])
        {
            int temp = nums[j];
            nums[j] = nums[j + 1];
            nums[j + 1] = temp;
        }
    }
}

Array.Sort(nums);//升序
Array.Reverse(nums);//反转

 

 

p72--82  --

1.方法 static 

 

 

 

//public 公共的
//static 静态的
//返回值 不需要返回值写 void
//方法名 Pascal
//return 退出;返回值
/// <summary>
/// 比大小,取大值
/// </summary>
/// <param name="n1"></param>
/// <param name="n2"></param>
/// <returns></returns>
public static int GetMax(int n1, int n2)
{ 
    return n1 > n2 ? n1 : n2;
}

2. static 方法中  out ref params 的用法

//out ref params
//return -- 返回同一类型的多个值
//out -- 返回不同、相同 类型的多个值 ;方法外赋值没意义
//ref -- 在方法外必须为其赋初始值,而方法内可以不赋值
//params -- 可变参数
//求数组中的最大值,最小值,和,平均数
int[] nums = { 1, 2, 3, 4, 5, 7, };
#region return--返回同一类型的多个值
        public static int[] GetNum(int[] nums) {
            int[] res = new int[4];
            res[0] = nums[0];//max
            res[1] = nums[1];//min
            res[2] = nums[2];//sum
            for (int i = 0; i < nums.Length; i++)
            {
                //最大值
                if (nums[i] > res[0])
                {
                    res[0] = nums[i];
                }
                //最小值
                if (nums[i] < res[1])
                {
                    res[1] = nums[i];
                }
                //
                res[2] += nums[i];
            }
            //平均数
            res[3] = res[2] / nums.Length;

            return res;
        }
        #endregion

#region out--返回不同、相同 类型的多个值  调用的时候加out == GetNum1(out max,out min...)
        public static void GetNum1(int[] nums, out int max, out int min, out int sum, out int avg ,out bool b, out string s,out double d)
        {
            max = nums[0];//max 方法内赋初值
            min = nums[0];//min 方法内赋初值
            sum = 0;//方法内赋初值

            for (int i = 0; i < nums.Length; i++)
            {
                //最大值
                if (nums[i] > max)
                {
                    max = nums[i];
                }
                //最小值
                if (nums[i] < min)
                {
                    min = nums[i];
                }
                //
                sum += nums[i];
            }
            //平均数
            avg = sum / nums.Length;

            b = true;
            s = "1";
            d = 1.12;
        }
        #endregion

#region ref 在方法外必须为其赋值,而方法内可以不赋值 Test(ref test1,ref test2);
        int test1 = 10;  //方法外部赋初值
        int test2 = 20;  //方法外部赋初值
        public static void Testref(ref int test1, ref int test2) 
        { 
            //方法内不赋值
            int temp = test1;
            test1 = test2;
            test2 = temp;
        }
        #endregion

#region params TestParams("张三",99, 88, 77)
public static void TestParams (string name, params int[] score)//params int[] score必须放到最后
        { 
            int sum = 0;
            for (int i = 0; i < score.Length; i++)
            {
                sum += score[i];
            }
            Console.WriteLine("{0}这次总成绩是{1}",name, sum);
        }

//例如:任意长度数组的最大值
int[] listNum = { 1, 2, 3, 4, 5 };//数组的的数字可以变化,且想放几个放几个
//int listSum = GetSum(listNum);

int listSum = GetSum(1,2,3,4);

public static int GetSum(params int[] n) { 
    int sum = 0;
    for (int i = 0; i < n.Length; i++)
    {
        sum += n[i];
    }
    return sum;
}
#endregion

 3. 感觉这位博主讲解得很到位

C#中ref、out类型参数的区别和params类型参数的用法 - 酷酷魔术师 - 博客园 (cnblogs.com)

  

p83 -- 方法的重载

#region 方法的重载:方法的名称相同,参数不同;参数个数相同,类型需不同;参数的类型相同,个数需不同;方法的重载和返回值没有关系
        //依次调用
        //StaticRe(1,2);
        //StaticRe(2.1,3);

        public static void StaticRe(int a ,int b) {
        
        }
        public static void StaticRe(double a, double b)
        {

        }
        #endregion

p84 -- 递归

        #region 方法的递归 :方法自己调用自己
        public static int i = 0;
        //找到文件夹中所有的文件
        //调用 TellStory();
        public static void TellStory() 
        { 
            Console.WriteLine("有座山");
            Console.WriteLine("讲故事");
            i++;
            if (i > 10)
            {
                return;
            }
            TellStory();
        }
        #endregion

0505.Net基础班第七天(函数) - liuslayer - 博客园 (cnblogs.com)

 

p

 

 

 

 

 

 

【01_C#入门到精通】新手强烈推荐:C#开发课程,一整套课程_哔哩哔哩_bilibili

posted @ 2022-02-23 18:18  驼七  阅读(414)  评论(0)    收藏  举报