方法、类成员的初始化
方法返回值不能满足,需要多个返回值时;
方法需要修改变量需带回原变量时;
代码可读性高,参数可交换位置
方法扩展时,目前不存在满足的方法
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;
}
}
}
参数拥有默认值
简化方法的调用,不需要额外声明数组