The using keyword is both a directive (this topic) and a statement.
For the using statement (i.e. to encapsulate the scope of an IDisposable object, ensuring that outside of that scope the object becomes cleanly disposed) please see Using Statement.
Access Static Members of a Class
Allows you to import a specific type and use the type's static members without qualifying them with the type name. This shows an example using static methods:
And this shows an example using static properties and methods:
Associate an Alias to Resolve Conflicts
If you are using multiple namespaces that may have same-name classes(such as System.Random and UnityEngine.Random), you can use an alias to specify that Random comes from one or the other without having to use the entire namespace in the call.
This will cause the compiler to be unsure which Random to evaluate the new variable as. Instead, you can do:
This doesn't preclude you from calling the other by it's fully qualified namespace, like this:
rnd will be a System.Random variable and unityRandom will be a UnityEngine.Random variable.
Associate an Alias with a Namespace
Reference a Namespace
Using alias directives
You can use using in order to set an alias for a namespace or type. More detail can be found in here.
This modified text is an extract of the original Stack Overflow Documentation created by following contributors and released under CC BY-SA 3.0