Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "T" mean in C#?

Tags:

c#

.net

generics

I have a VB background and I'm converting to C# for my new job. I'm also trying to get better at .NET in general. I've seen the keyword "T" used a lot in samples people post. What does the "T" mean in C#? For example:

public class SomeBase<T> where T : SomeBase<T>, new() 

What does T do? Why would I want to use it?

like image 237
Jim Avatar asked Dec 30 '08 14:12

Jim


People also ask

What is \t used for in C?

\t (Horizontal tab) – We use it to shift the cursor to a couple of spaces to the right in the same line.

What does T stand for in programming?

T is a simple object-oriented programming language, modeled on Java. T supports only one primitive type, the integer type. T also supports reference types via the class Object, which is the root of the inheritance hierarchy. T supports only single-inheritance. T syntax is derived from Java syntax.

Why do we use \t in C++?

It is used to move the cursort the next line. '\t' is a horizontal tab . It is used for giving tab space horizontally in your output.

What does T stand for in C++?

class T is a template parameter, a function-definition with a template parameter is a function-template and a class-definition with a template parameter is a class-template.


2 Answers

It's a symbol for a generic type parameter. It could just as well be something else, for example:

public class SomeBase<GenericThingy> where GenericThingy : SomeBase<GenericThingy>, new() 

Only T is the default one used and encouraged by Microsoft.

like image 61
user39603 Avatar answered Sep 19 '22 03:09

user39603


T is not a keyword per-se but a placeholder for a generic type. See Microsoft's Introduction to Generics

The equivalent VB.Net syntax would be:

Public Class SomeBase(Of T As {Class, New})) 
like image 36
Rob Walker Avatar answered Sep 21 '22 03:09

Rob Walker