在 UnityScript 中使用 LINQ SUM 的正确语法是什么

问题描述 投票:0回答:1

您好,我正在尝试找出在 unityscript 中使用 LINQ 从类列表中获取总和的正确语法

var totalCount: int;

class munsters {
 var beast: String;
 var min: int = 1;
 var max: int =1;
}

var wilds: List.<munsters>;

//this gives me the error -- 
//InvalidProgramException: Invalid IL code in OppSpawnTester:OnDrawGizmos (): IL_0007: ldarg.1   
totalCount = wilds.Sum(function(a) a.max);

linq sum unityscript
1个回答
0
投票

totalCount = wilds.Select(function(a : munsters) a.max).ToList().Sum();

对于仍然持有 unityscript 的其他人:)

© www.soinside.com 2019 - 2024. All rights reserved.