C# Game Programming: For Serious Game CreationC#2.0
C# version 2.0 added generics and anonymous delegates. Its easiest to explain
these new features with examples.
Generics
Generics are a way of writing code to use some general object with some general
properties, rather than a specific object.Generics can be used with classes,
methods,interfaces,and structs to define what data type they will use.The data
types used with generic code are specified at compile time, which means the
programmer no longer has to be responsible for writing test code to check that
the correct data type is being used. This in turn makes the code shorter because
test code doesn't need to be written, and safer because it reduces type mismatch
errors at runtime. Generic code also tends to be faster because less casting be-
tween data types has to be performed.
The following code is written withoutt he use of generics
โหลดเพิ่มเติมคัฟCode:ArrayList_list = newArrayList( ) ; _list.Add(1.3) ; // boxing converts value type to a reference type _list.Add(1.0) ; //Unboxing Converts reference type to a valuetype. object objectAtPositionZero =_list [0] ; double valueOne = (double)objectAtPositionZero ; double valueTwo = (double)_list[1] ;
Unhidden Content - Enjoy The View!**Hidden Content: Thanks to see the content**