Game Development Reference
In-Depth Information
C#:
//with out Generic
var someScript : MyScript = (MyScript)GetComponent(typeof(MyScript));
//or using the Generic version in C#
var someScript : MyScript = GetComponent<MyScript>();
The foreach keyword
C# iterators use foreach instead of for . Also, noice the variable declaraion within
the for / foreach statement. C# requires the type of the item contained in the list to be
explicitly declared.
JavaScript:
for (var item in itemList) {
item.DoSomething();
}
C#:
foreach (ItemType item in itemList) {
item.DoSomething();
}
Although the JavaScript version uses inefficient dynamic
typing (since you can't declare the type), the staic-typed
alternaive is as follows.
JavaScript:
for (var item = itemList.GetEnumerator(); item.MoveNext();) {
item.DoSomething();
}
 
Search WWH ::




Custom Search