Game Development Reference
In-Depth Information
Generics
The C# syntax supports generics that allow you to use classes and methods, which do not
specifically declare a type. Instead, the type is passed as a parameter when calling the
method or instantiating the class at runtime.
.Net comes with some useful generic classes such as List and Dictionary , and Unity's
own API has some generic functions. They remove the need for some of the verbose cast-
ing, which would otherwise be necessary in C#, as follows:
// JavaScript user:
//Automatically cast the correct type
var someScript : MyScript = GetComponent(MyScript);
//or using the Generic version in JavaScript
var someScript : MyScript = GetComponent.<MyScript>();
// C# user:
//with out Generic
MyScript someScript =
(MyScript)GetComponent(typeof(MyScript));
//or using the Generic version in C#
MyScript someScript = GetComponent<MyScript>();
Search WWH ::




Custom Search