Generics

The C# syntax supports generics that allows 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 the List and Dictionary, and Unity's own API has some generic functions, which remove the need for some of the verbose casting that would otherwise be necessary in C#.

JavaScript:

//Automatically cast the correct type
var someScript : MyScript = GetComponent(MyScript);

//or using the Generic version in Javascript
var someScript : MyScript = GetComponent.<MyScript>();

C#:

//with out Generic
var someScript : MyScript = (MyScript)GetComponent(typeof(MyScript));
//or using the Generic version in C#
var someScript : MyScript = GetComponent<MyScript>();
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.126.199