Why is System.Collections included as a namespace when you create a C# script through the editor?

As far as I can see it’s not used at all by the skeleton script created, I’m not sure what its purpose is being there and it’s mildly annoying that I have to keep deleting it after creating a new script…

It’s because it’s pretty common to use coroutines, and IEnumerator is part of System.Collections.

It seems you’re coming from a C++ background. In C++ an include statement will literally insert the other file at the position of the include. In C# there is nothing like that. A using statement is “just” a shortcut for a namespace. To access a certain namespace it has to be part of your project. You can’t use anything that’s not already available to your project.

For example instead of:

    using System.Collections.Generic;
    
    // [...]
    
    List<int> m_MyList;

you can write:

    System.Collections.Generic.List<int> m_MyList;

using just let you kind of “map” the classnames available in a certain namespace into your global namespace. Namespaced are used to avoid conflicts of classes with the same name. For example the .NET / Mono framework comes with a Random class. This class is placed into the “System” namespace. Unity comes with it’s own Random class which is placed into the UnityEngine namespace.

Both classes are avaliable to your application because unity links it’s own assembly (UnityEngine.dll) as well as most default framework librarys (mscorelib.dll, System.dll, …).

So both classes are there and you can use them at any time by using the full classname:

    private System.Random m_MyRandomInstance = new System.Random();

or

    int someValue = UnityEngine.Random.Range(0,10);

using just allows you to omit the namespace in code. You can get into trouble when you use two using statements which contain the same classes since the compiler can’t tell which one you want to use.

using UnityEngine;
using System;

Random...  //Compiler error "ambiguous reference"

Like Eric said the System.Collections namespace includes some basic collections which are used by unity. The most common interface is the IEnumerator which is used for coroutines in unity.

twistedoakstudios.com/blog/Post404_script-templates-and-base-classes

Well. You can change the template.