C#参数使用场景简要说明

C#参数使用场景简要说明

1、传值参数

方法、类成员的初始化

2、输出参数

方法返回值不能满足,需要多个返回值时;

3、引用参数

方法需要修改变量需带回原变量时;

4、具名参数

代码可读性高,参数可交换位置

5、方法扩展(this参数)

方法扩展时,目前不存在满足的方法

csharp 复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Linq;
//this参数(扩展方法)
namespace PamametersExample9
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> vs = new List<int>() { 11, 21, 13, 1, 15 };
            bool b = AllCreateThanTen(vs);
            //lambda表达式
            bool b1 = vs.All(i => i > 10);
            Console.WriteLine(b);
            Console.WriteLine(b1);
        }
        static bool AllCreateThanTen( List<int> vs)
        {
            foreach (var item in vs)
            {
                if (item <= 10)
                {
                    return false;
                }
            }
            return true;
        }
    }
}

6、可选参数

参数拥有默认值

7、数组参数

简化方法的调用,不需要额外声明数组

相关推荐
qq_4312807019 小时前
上位与基恩士PLC通讯工作记录
c#
weixin_428005301 天前
C#调用 AI学习从0开始-第1阶段(基础与工具)-第2天Prompt工程基础
人工智能·学习·c#·prompt
咩图1 天前
WPF-VisualStudio-C#-Fluent.Ribbon8.0.0学习
c#·wpf·visual studio
加号31 天前
【C#】WPF基于Halcon 的HWindowControlWPF 控件实现图像缩放、移动
开发语言·c#·wpf
雪豹阿伟1 天前
2.C# —— 结构体、类型转换与运算符
c#·上位机
njsgcs1 天前
c# solidworks GetPartBox无法获得正确实体边界框原因
开发语言·c#·solidworks
rockey6271 天前
AScript之匿名类型与动态类型
c#·.net·script·eval·expression·动态脚本
99乘法口诀万物皆可变1 天前
BMS HIL 自动化测试框架方案(基于 CANoe + C# + Excel)
开发语言·c#·excel
祀爱1 天前
定时任务之BackgroundService的详细教程
后端·c#·asp.net
weixin_428005301 天前
C#调用 AI学习从0开始-第1阶段(基础与工具)-第3天FewShot少样本测试
人工智能·c#