- Home /
C# generics and getters/setters with Unity iPhone
Is there any reason why I shouldn't use generics and/or getters and setters in Unity for iPhone?
Any performance hitsI should be expecting?
Nothing unexpected. Generics lists and dictionaries are probably faster than there non-generic counter parts.
It depends by what you mean by counterparts. They're not as fast as built-in arrays, but built-in arrays are only good when you don't need reshuffling of data. Definitely go with Lists over ArrayLists, though. As for getters/setters being faster than what? functions?, I have no idea, but I highly doubt the difference would make any real-world difference, and using a property ins$$anonymous$$d of a function can make for more readable code.
Since I don't understand the compiling process fully I though there might be some extra work involved with using get and set. But if getters and setters compile into functions I guess no harm in using them than. AFAI$$anonymous$$ built in arrays are cheaper than generic lists but I'm not talking about hundred of items per list. I'm more interested in making my code more readable. Thanks for the input!
Answer by Jessy · Dec 25, 2010 at 10:26 PM
No.
However, in my experience, if you use too many C#-specific features, such as what you mentioned, event handlers, and lambda expressions, the game won't run on the device, despite running fine in the Editor. You'll get a SIGABRT error, and one frame won't even be rendered (as can happen with a SIGBUS). The Unity logo will be seen, if you don't have Pro, but that's it. Support has not been able to give me any guidelines on this. Everything works in isolation; it comes from everything adding up, as far as I can tell. Because I can't run a game that I put a lot of work into already, I am starting a new project, with the assumption that this will happen, as it gets more complex; I will be building frequently, trying to identify the straw of code that breaks the Unity iOS's back. I will try to remember to update about that, here, when it happens.
Interesting. So no big deal if I use a list every now and then but I should't overdo it with C# specifics. Thanks for the insight Jessy.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Properties names, same as class okay or bad? 1 Answer
How do I invert the Y axis in Penelope tutorial? 3 Answers
Accessing class properties through getters & setters in editor mode 1 Answer
How could I create a dynamic cartoon style speech bubble? 1 Answer