- Home /
[Syntax] LINQ Query Operations in UnityScript ( Js )
How do Linq expressions work in JS?
I've attempted this but the synax is C# so its obviously throwing some compiler exceptions
var participantResigned = from participant in match.participants
where participant.matchOutcome == GKTurnBasedMatchOutcome.Quit
select participant;
Could anyone give me an example of using there query methods in JS?
Thanks, Caius.
Answer by Caiuse · Jul 25, 2012 at 10:52 AM
answer to my own question:
var participantResigned = match.participants.Where(function(participant){ return participant.matchOutcome == GKTurnBasedMatchOutcome.Quit; })
.Select(function(participant){ return participant; });
Untested but no compiler errors.
@whydoidoit One problem, I can't set the return type, it returns System.Linq.Enumerable+c__Iterator10`2[myItem,myItem]
You want a .FirstOrDefault() or a .First() at the end. Actually you don't need the select at all on reflection to get a single one. To get an array or list add a ToArray() or ToList() to the end.
var participantsResigning = match.participants.Where(function(participant) { return participant.matchOutcome == G$$anonymous$$TurnBase$$anonymous$$atchOutcome.Quit; }).ToArray();
var participantResigned = match.participants.FirstOrDefault(function(participant) { return participant.matchOutcome == G$$anonymous$$TurnBase$$anonymous$$atchOutcome.Quit; });
if(participantResigned != null) {
}
Your answer
Follow this Question
Related Questions
script default variable value behaviour 2 Answers
How to declare a list of lists in JS? 2 Answers
Error in my script i don't understand. 0 Answers