Link to home
Start Free TrialLog in
Avatar of pzozulka
pzozulka

asked on

C#: Generics

I am a beginner in C#, and just started learning about Generics. I was doing some code review and ran across this:
List<string> myList = new List<string>();

Open in new window

Just by looking at it, how can I determine if it's a generic list or a regular list?

Also, the book says a Generic type's naming convention says the type should start with a T. What if the code is not following normal naming conventions. Is there anything that tells you this is a generic type -- without writing any code to check if it is or isn't.
ASKER CERTIFIED SOLUTION
Avatar of Craig Wagner
Craig Wagner
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pzozulka
pzozulka

ASKER

A regular List doesn't actually exist in the .NET framework.
Are you saying I can't do:
List myL = new List();

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
By the way T can be anything you want it to be...
I would add, though, that there are ways to restrict the type(s) to fitting a certain criteria. Generic type constraints can be used to restrict the types that can be used with your custom generic classes.

**I mention generic type constraints only to make you aware of them. Focus on the basics first. Once you grasp those, then move on to constraints.
Are you saying I can't do:
List myL = new List();

Have you tried it? What happened when you did? If you're wondering what's going to happen if you try something, just try it. You'll learn more than having someone spoon-feed you the answer. Besides, the compile is a much better compiler than asking people on a forum to compile your code.