如何打印序列中的最后一个数字以及它在for循环中运行的次数?
int numOne = 50;
for (int i = 0; i < numOne; i++)
{
Console.WriteLine(i);
}
答案 0 :(得分:3)
var list = new List<int> { 1, 2, 3, 6, 10, 1, 5, 1 };
var lastItem = list.Last();
Console.WriteLine("{0} {1}", lastItem, list.Count(item => item == lastItem));