0

Hello I'm trying to figure out the correct syntax for getting the sum from a class list using LINQ in unityscript

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);

1 Answer 1

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

For anyone else still holding on the unityscript :)

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for contributing to the Stack Overflow community. This may be a correct answer, but it’d be really useful to provide additional explanation of your code so developers can understand your reasoning. This is especially useful for new developers who aren’t as familiar with the syntax or struggling to understand the concepts. Would you kindly edit your answer to include additional details for the benefit of the community?
For anyone else still holding on the unityscript .. why would you though? ^^ This has been deprecated long ago ^^

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.