C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
.NET
ADO.NET
Android
ASP.NET
C#
Databases & DBA
Design Patterns & Practices
iOS
Java
OOP/OOD
SharePoint
Software Testing
Web Development
WPF
View All
4
Reply
What is Generics?
Yogesh Jadhav
12y
2.9k
1
Reply
Delete Row
Delete Column
Insert Link
×
Insert
Cancel
Embed YouTube Video
×
Width (%)
Height (%)
Insert
Cancel
Table Options
×
Rows
Columns
First row as header
Create Table
Insert Image
×
Selected file:
Alignment
Left
Center
Right
Select an image from your device to upload
Upload to Server
Cancel
Submit
Generics were added to 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:
// Declare the generic class.
public class GenericList
{
void Add(T input) { }
}
class TestGenericList
{
private class ExampleClass { }
static void Main()
{
// Declare a list of type int.
GenericList
list1 = new GenericList
();
// Declare a list of type string.
GenericList
list2 = new GenericList
();
// Declare a list of type ExampleClass.
GenericList
list3 = new GenericList
();
}
}
Yogesh Jadhav
12y
1
Generics are the type safe programs. We can reduce the code.We can pass datatypes at Runtime. Ex: private T[] Sort(T[] input) {return input; }
satish kumar
10y
0
Java generics were introduced in 2004 with Java 5. It has been around for eight years now, but Java generics still pose problems for experienced developers and newcomers alike. Beginners often find Java generics to be counterintuitive. I think it must be difficult to learn Java generics if you don't have the pre-generics perspective first. It's hard to understand some of Java generics' limitations if you don't have a firm grasp of Java code without generics. Experienced developers often have only a rough idea of what Java generics do. They don't want to dig into the details and are often surprised by generics behavior.
Sanjay Singh
11y
0
Generics allow you to define type-safe data structures, without committing to actual data types.generics are similar to C++ templates, but are drastically different in implementation and capabilities.By using this concept you get to reuse data processing algorithms without duplicating type-specific code.
PAUL K
11y
0
How to use Dictionary class in Systems.Collections.Generic?
What are the locations of deploying an assembly?
Message