您的位置:首页 > 房产 > 家装 > C#参数使用场景简要说明

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

2024/10/6 20:38:17 来源:https://blog.csdn.net/qdacm_lxg/article/details/139676438  浏览:    关键词:C#参数使用场景简要说明

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

1、传值参数

方法、类成员的初始化

2、输出参数

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

3、引用参数

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

4、具名参数

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

5、方法扩展(this参数)

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

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

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

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com