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、数组参数

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

相关推荐
农村小镇哥4 小时前
C#中的字符串格式化
服务器·开发语言·c#
czhc11400756638 小时前
719:StartPoint;Margin;ResourceDictionar;Component.model;lds;
c#
-银雾鸢尾-10 小时前
C#中的万物之父——Object类
开发语言·c#
水晶石NSIS专栏10 小时前
Geek_Studio - 安卓终端调试工作台
android·c#·apk签名·coloros主题
-银雾鸢尾-10 小时前
C#中的继承
开发语言·c#
吴可可12321 小时前
C#AutoCAD二次开发打断多段线
c#
-银雾鸢尾-1 天前
里氏替换原则
开发语言·c#·里氏替换原则
-银雾鸢尾-1 天前
C#中的索引器
开发语言·c#
en.en..1 天前
冒泡排序与选择排序完整对比解析
开发语言·数据结构·算法·c#·排序算法
geovindu1 天前
CSharp: Decorator Pattern
开发语言·后端·c#·装饰器模式·结构型模式