- Home /
problem with enumerables in loop !
My for in loop is causing Application Exception: Argument is not enumerable (does not implement System.Collections.IEnumerable).
I'm going through a class of floats with for in loop like so:
class myClass { var variables : float; }
var theClass = new myClass();
for (var f : float in theClass) {
}
Is for in loop not good for classes? Aren't they enumerable?
Answer by Tourist · Dec 13, 2012 at 10:15 AM
'theClass' must be a collection to iterate on.
What is the purpose of the for loop? Maybe there is a better way to do what you want to.
I want to add the floats in the class cumulatively by iteration. I need to check every step if a tolerance (another float) is exceeded. And I need to know in which iteration it was exceeded.
a class is a declarative structure that can not be modified this way. You should use a collection. Here is a link to some collections you could use ins$$anonymous$$d of your class 'myClass' : http://wiki.unity3d.com/index.php?title=Which_$$anonymous$$ind_Of_Array_Or_Collection_Should_I_Use%3F#Javascript_Arrays
All right, thanks. That's what I came to suspect. I have to copy the structure into a collection to make it happen. Thanks anyway.
Your answer

Follow this Question
Related Questions
System.NullReferenceException 1 Answer
many "characters" data 3 Answers
Serializable class variables loose Gameobject reference in inspector 0 Answers
Question about classes C# 1 Answer
Changing class variables 2 Answers