A view on C# Generics

.NET Generics has wide vareity of applications, from generic collection classes to custom user created collection classes.
An object based collection has boxing/unboxing overhead for value types, casting overhead for reference type this means type safety can be compromised & may be runtime exceptions will happen. Writing a collection class for every type will lead to lesser productivity. In Non-generic list value types needs to be boxed & reference types needs to be casted hitting performance. Also accidentallly unwarranted type can enter in to list throwing runtime exception because weekly typed it is. A generic class can defer specification of one more types until it is instantiated. (For example a generic type T may be an int or string)

Generics after compiling in CIL it will contain only type value parameters. But during compilation by CLR to create instance of generic class, the handling is different for value type and reference type. For value type for every distinct type T a generic specialized class will be created with proper substitutions. For example for int & long, separately substituted two generic specialized class will be created. For reference types things are different. On encountering usage of first reference type a single specialized generic type will be created substituting object pointers. For example customer, order classes will be instances of same substituted specialized generic type. This reduces code bloating instead of a class for every Type, same generalized substituted Type class is re-used.

Default keyword will be used like default for returning 0 for value & null for reference types. “where” keyword limits use of specific generic placeholders on a generic type. A constraint specified with ‘where’ keyword can limit what could be the generic Type T can be. For example it can limit that to MyClass, so only many code logic (like comparisons or operator overload) will work on it.

Good book on COM

I am reading Don's book Essential COM. Preface is fairly intresting.
The author argues on the definition of object orientedness.
C++ => OO => (some) Encapsulation + (some)Polymorphism + (some)Late Binding + Implementation Inheritance
COM => OO => (Real)Encapsulation + (Real) Polymorphism + (Really)Late Binding + Interface Inheritance

Eagle's eye on view datastructures

A data structure is collection of organized data and appropriate functions to operate on that data. STL offers many of common data structures in C++. System.Collections & System.Collections.Generic is the nearest C# equivalent. Stack is one of the simplest data structure based on Last in first out concept (LIFO). Queue is another one based on First in first out concept(FIFO). Stacks & Queue in general are based on arrays so of fixed size. This is the reason where linked list comes into play. Again in general the above data structures did not deal with any relationships between them, that is why Trees are there. They can represent data relationships hierarchically.