- Home /
Using System.Collections.Generic;
Just a curious question.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
This is what I often show from scripts that have lists. Why do we need System.Collections when we have System.Collections.Generic?
Answer by Eric5h5 · Sep 14, 2014 at 03:05 AM
Because Systems.Collections contains IEnumerator, which you use for coroutines.
Of course, if you're not using coroutines in a particular script, then there's no reason to import System.Collections that I can think of. It doesn't hurt anything to have it there just in case, though.
And I suppose to be totally obvious we should mention that Systems.Collections.Generic does not contain IEnumerator.
Answer by Kiwasi · Sep 14, 2014 at 03:59 AM
This may not be super obvious, but including Systems.Collections does not automatically include Systems.Collections.Generic
You could do
Systems.Collections.Generic.List<myClass> myList;
But that's a lot of unneeded typing every time you make a list.
You actually cannot do the former. Unity is refusing to compile when I did it a few $$anonymous$$utes ago.
Yes, but the question was "if I'm importing System.Collections.Generic, what's the point of importing System.Collections?"
Thanks @Bluntweapon. I had no idea if it would work or not. Will remove it from my answer.