generics in c#
-
what are generic in c#
Ashwani
-
what are generic in c#
Ashwani
its a new feature in c#2.0
Ashwani
-
its a new feature in c#2.0
Ashwani
it avoids object type casting
Ashwani
-
what are generic in c#
Ashwani
Have a look at Wikipedia's article on generic programming[^]. It's a broad article, but still applies to C#.
Tech, life, family, faith: Give me a visit. I'm currently blogging about: Rabbi Kadouri Meets Messiah? The apostle Paul, modernly speaking: Epistles of Paul Judah Himango
-
what are generic in c#
Ashwani
-
it avoids object type casting
Ashwani
:confused::confused::doh::doh: Whats this ? question is yours and replies are also from your side Take a look Generics are classes, structures, interfaces, and methods that have placeholders (type parameters) for one or more of the types they store or use. A generic collection class might use a type parameter as a placeholder for the type of objects it stores; the type parameters appear as the types of its fields, and the parameter types of its methods. A generic method might use its type parameter as the type of its return value, or as the type of one of its formal parameters. The following code illustrates a simple generic class definition. Visual Basic Copy Code Public Class Generic(Of T) Public Field As T End Class C# Copy Code public class Generic { public T Field; } C++ Copy Code generic public ref class Generic { public: T Field; }; When you create an instance of a generic class, you specify the actual types to substitute for the type parameters. This establishes a new generic class, referred to as a constructed generic class, with your chosen types substituted everywhere that the type parameters appear. The result is a type-safe class tailored to your choice of types, as the following code illustrates. Visual Basic Copy Code Dim g As New Generic(Of String) g.Field = "A string" C# Copy Code Generic g = new Generic(); g.Field = "A string"; C++ Copy Code Generic^ g = gcnew Generic(); g->Field = "A string"; The following terms are used to talk about generics in the .NET Framework: A generic type definition is a class, structure, or interface declaration that functions as a template, with placeholders for the types it can contain or use. For example, the Dictionary class can contain two types: keys and values. Because it is only a template, you cannot create instances of a class, structure, or interface that is a generic type definition. Generic type parameters, or type parameters, are the placeholders in a generic type or method definition. The Dictionary generic type has two type parameters, TKey and TValue, representing the types of its keys and values. A constructed generic type, or constructed type, is the result of specifying types for the generic type parameters of a generic type definition. A generic type argument is any type that is substituted for a generic type parameter. The general term "generic type" includes both constructed types and generic type