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?
\t (Horizontal tab) – We use it to shift the cursor to a couple of spaces to the right in the same line.
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.
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.
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.
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.
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}))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With