Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 189625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:11:18+00:00 2026-05-11T16:11:18+00:00

Duplicate of What is the "< >" syntax within C# Actually i want to

  • 0

Duplicate of What is the "< >" syntax within C#


Actually i want to know ‘why and when should i use generics?’.

What is the need for it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T16:11:18+00:00Added an answer on May 11, 2026 at 4:11 pm

    Generics are a way of ensuring Type Safety at Compile time in C#.

    Example- Pre-Generics:

    class Person 
    {
     string name;
     string lastname;
     public Person(string _name )  { this.name = _name; }
    }
    
    class ClientCode
    {
       public static void Main()
       {
             //create a list of person
             ArrayList personList = new ArrayList();
             Person p1 = new Person("John");
             Person p2 = new Person("Ram");
             personList.Add(p1);
             personList.Add(p2);
             // BUT, someone can do something like:
             // ArrayList does not stop adding another type of object into it
             object q = new object();
             personList.Add(q);
             // while accessing personlist
             foreach(object obj in personlist)
             {
                Person p = obj as Person;
                // do something, for person
                // But it will fail for last item in list 'q' since its is not person.
             }
       }
    }
    

    Example- Post-Generics:

    class ClientCode
    {
       public static void Main()
       {
             //create a list of person
             List<Person> personList = new List<Person>();
             Person p1 = new Person("John");
             Person p2 = new Person("Ram");
             personList.Add(p1);
             personList.Add(p2);
             // Someone can not add any other object then Person into personlist
             object q = new object();
             personList.Add(q); // Compile Error.
             // while accessing personlist, No NEED for TYPE Casting
             foreach(Person obj in personlist)
             {
                // do something, for person
             }
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: When should I use double or single quotes in JavaScript? Do ""
I know this is almost a duplicate of : The error "Login failed for
Possible Duplicate: Inadvertent use of = instead of == C++ compilers let you know
I know this is a duplicate question. but i want know it with an
Duplicate post, see: When do you use the "this" keyword? On almost every project
I know that this might be a duplicate of: Return a "NULL" object if
Duplicate of: There is a function to use pattern matching (using regular expressions) in
Possible Duplicate: Array versus List<T>: When to use which? Is there any best practice
Duplicate of "INSERT IGNORE" vs "INSERT ... ON DUPLICATE KEY UPDATE"
Possible Duplicate: Converting ereg expressions to preg <?php $searchtag = "google"; $link = "http://images.google.com/images?hl=de&q=$searchtag&btnG=Bilder-Suche&gbv=1";

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.