我想获得public T getItem(int position) {
return mObjects.get(position); // mObjects references same ArrayList as users
}
字段的总和。
users.get(position)
答案 0 :(得分:1)
以下是一些使用System.Linq;
的实例void Main()
{
List<int> numbers = Enumerable.Range(1,100).ToList();
var result = numbers.Sum();
Console.WriteLine(result); // Prints 5050
List<SomeType> customTypeList = Enumerable.Range(1, 100).Select(x => new SomeType { SomeVal = x}).ToList();
var customResult = customTypeList.Sum(n => n.SomeVal);
Console.WriteLine(result); // Prints 5050
}
public class SomeType
{
public int SomeVal { get; set;}
}