C# 2.0 Generics

N

Nicholas Paldino [.NET/C# MVP]

Sahil,

It is just common practice, where T is short for "Type", which is what
you are supplying to the Generic. It is a holdover from C++ templates, I
believe, but there is no requirement that you name it "T". However, the
naming guidelines for .NET might end up suggesting that you use T, as
opposed to something else (since it is publically accessible, it is subject
to the public naming guidelines).

Hope this helps.
 
S

Sriram Krishnan

I remember some blog post which talked about how there was huge internal
discussions on whether this is a good practice. You see, its ok as long as
you stick to T and K. But what happens when you have more than 2 parameters?

Some one dig up the blogs.msdn.com post for me, please :)
 
J

Jon Skeet [C# MVP]

Sriram Krishnan said:
I remember some blog post which talked about how there was huge internal
discussions on whether this is a good practice. You see, its ok as long as
you stick to T and K. But what happens when you have more than 2 parameters?

"T" usually just means "Type" as in "well, there's nothing particularly
significant about it". "K" usually means "Key" and "V" usually means
value. (K and V usually come together.)

Once you've got past those, I think you've exhausted 95% of the real
life uses of generics, to be honest. You can use anything you like, of
course...
 
J

James Curran

Typically in C++ templates, T is used for the first, and U for the
second (particularly when the type truly could be nearly any type), which
covers the vast majority of templates. If a template needed more than that
(or if only a certain category of class could be used), usually, a
multi-letter Id is used which more closely indicates the purpose of it in
the template -- just as one would with parameters to a function.

--
Truth,
James Curran
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
(note new day job!)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top