Generics Articles

C# 4.0 – Covariance and Contravariance of Generics

Covariance allows casting of generic types to the base types, for example, IEnumerable<X> will be implicitly convertible an IEnumerable<Y> if X can implicitly be converted to Y. // List of strings IList<string> stringList = new List<string>(); // We can convert it to an Enumerable collection IEnumerable<object> Obj= strings; For this purpose IEnumerable is marked with […]

Read more

Generics in C#

In my last article I focused on issues of typesafety and reusability when using ArrayLists.In this article we shall focus on how these issues of type safety andreusability are very nicely handled by Generics. All with the help ofcode again : using System; using System.Collections.Generic; using System.Text;   namespace GenericsSample { class Person { int […]

Read more

Generics in C#

Generics are new feature provided with version2.0 of the Microsoft.Net framework. Generic classes and methods combinere-usability, type safety and efficiency in a way that therenon-generics counterparts do not/cannot. In this part some features of ArrayLists andthere shortcomings/limitations will be discussed. The contained in thisarticle has been written in Visual Studio 2005 in C#. Earlier ArrayLists […]

Read more

C# Generics – An Introduction

There is a reality; most of the developers confuse about C# Generics. Actually, there is no reason for that. If your background comes from C++ or Java you may understand more easily. Wha t tell you from your C++ knowledge o r from Java. Main concept is same here in C# with some better extensions […]

Read more

Understanding C# Generics

  Introduction Before we starttampering around the code, lets understand why we need a generic type? Well inmost of application development we come across lots of situation where we need atype which can hold both value types and reference type. In this situation weneed a generic type which can do both. Before we start working […]

Read more