110,571
社区成员
发帖
与我相关
我的任务
分享
Index i1 = 3; // 下标为 3 的元素
Index i2 = ^4; // 倒数第 4 个元素
int[] a = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
var rangeFromP = a[i1..i2] // 得到 3, 4, 5 (即:左闭右开区间)
IEnumerable<string> GetEnrollees()
{
foreach (var p in People)
{
if (p is Student { Graduated: false, Name: string name }) yield return name;
}
}
var area = figure switch
{
Line _ => 0,
Rectangle r => r.Width * r.Height,
Circle c => c.Radius * 2.0 * Math.PI,
_ => throw new UnknownFigureException(figure)
};
Point[] ps = { new (1, 4), new (3,-2), new (9, 5) }; // all Points
private List<int> _list = new ();