GENERICS IN DOT NET 3.5

Posted by Niranjan11 under Others on 7/31/2012 | Points: 10 | Views : 2954 | Status : [Member] | Replies : 13
Hi all


what are generics and how they are useful to us in programming especially in c# sharp


thanking you


cheers


have a nice day
Best Regards
niranjan yadav b

reagards
niranjan



Responses

Posted by: Oswaldlily on: 7/31/2012 [Member] Starter | Points: 25

Up
0
Down
http://www.c-sharpcorner.com/uploadfile/Ashush/generics-in-C-Sharp-part-i/

Niranjan11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: CGN007 on: 7/31/2012 [Member] Silver | Points: 25

Up
0
Down
1.http://msdn.microsoft.com/en-us/library/ms379564%28v=vs.80%29.aspx

Niranjan11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: CGN007 on: 7/31/2012 [Member] Silver | Points: 25

Up
0
Down
2.http://www.csharp-station.com/Tutorial/CSharp/Lesson20

Niranjan11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: CGN007 on: 7/31/2012 [Member] Silver | Points: 25

Up
0
Down
3.http://www.codeproject.com/Articles/8360/Generics-in-C-2-0

Niranjan11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: CGN007 on: 7/31/2012 [Member] Silver | Points: 25

Up
0
Down
Generics are a new feature in version 2.0 of the C# language and the common language runtime (CLR). Generics introduce to the .NET Framework the concept of type parameters, which make it possible to design classes and methods that defer the specification of one or more types until the class or method is declared and instantiated by client code. For example, by using a generic type parameter T you can write a single class that other client code can use without incurring the cost or risk of runtime casts or boxing operations, as shown here:
C#

// Declare the generic class
public class GenericList<T>
{
void Add(T input) { }
}
class TestGenericList
{
private class ExampleClass { }
static void Main()
{
// Declare a list of type int
GenericList<int> list1 = new GenericList<int>();

// Declare a list of type string
GenericList<string> list2 = new GenericList<string>();

// Declare a list of type ExampleClass
GenericList<ExampleClass> list3 = new GenericList<ExampleClass>();
}
}

Source:http://msdn.microsoft.com/en-us/library/512aeb7t%28v=vs.80%29.aspx

Niranjan11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: CGN007 on: 7/31/2012 [Member] Silver | Points: 25

Up
0
Down
Mark as answer if it helps...,That motivates...!!!

Niranjan11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajkatie on: 8/2/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
You can also refer video from following url
http://www.youtube.com/watch?v=7bKhAJpY9ho&list=PL54B7EC34478B0073&index=5&feature=plpp_video

Rajesh Patel
.Net Trainer(M.C.S.A | MCT)
Brainbench (Asp.Net 4.5 and C# 5.0)

Niranjan11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhsinathk on: 9/14/2012 [Member] Bronze | Points: 25

Up
0
Down
Generic classes have type parameters. Several separate classes in a C# program, each with a different field type in them, can be replaced with a single generic class. The generic class introduces a type parameter. This becomes part of the class definition itself.

using System;

class Test<T>
{
T _value;

public Test(T t)
{
// The field has the same type as the parameter.
this._value = t;
}

public void Write()
{
Console.WriteLine(this._value);
}
}

class Program
{
static void Main()
{
// Use the generic type Test with an int type parameter.
Test<int> test1 = new Test<int>(5);
// Call the Write method.
test1.Write();

// Use the generic type Test with a string type parameter.
Test<string> test2 = new Test<string>("cat");
test2.Write();
}
}

Niranjan11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhsinathk on: 9/14/2012 [Member] Bronze | Points: 25

Up
0
Down
Please Mark as Answer if it helpful to you..That helps others who search the same...

Niranjan11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 9/17/2012 [Member] Starter | Points: 25

Up
0
Down
Good Explanation Muhsinathk

Thanks & Regards
Hari

Niranjan11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 9/17/2012 [Member] Starter | Points: 25

Up
0
Down
Good Explanation CGN007


Thanks & Regards
Hari

Niranjan11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhsinathk on: 9/17/2012 [Member] Bronze | Points: 25

Up
0
Down
Thanks Mr.Hari

Niranjan11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hariinakoti on: 9/17/2012 [Member] Starter | Points: 25

Up
0
Down
welcome Muhsinathk

Thanks & Regards
Hari

Niranjan11, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response