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?
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?
Because Systems.Collections contains IEnumerator, which you use for coroutines.
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 minutes ago.
– BluntweaponYes, but the question was "if I'm importing System.Collections.Generic, what's the point of importing System.Collections?"
– Eric5h5
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.
– Eric5h5And I suppose to be totally obvious we should mention that Systems.Collections.Generic does not contain IEnumerator.
– Kiwasi