例如:我的列表包含:[5, 4, 3, 2, 1],我想每个值减1,新列表将是:[4, 3, 2, 1, 0],有可能,在 C# 中?
了解如何减少 List 中的值,如果可能的话,使用 List 函数或 LINQ。
using System;
class Program
{
static void Main()
{enter code here
int[] testArray = { 1, 2, 3 };`enter code here`
Console.WriteLine(string.Join(", ", testArray));
testArray = DecArray(testArray);
Console.WriteLine(string.Join(", ", testArray));
}
static int[] DecArray(int[] a)
{
for (int i = 0; i < a.Length; i++)
{
a[i]--;
}
return a;
}
}