“T"是什么意思在 C# 中是什么意思?

“T

问题描述:

我有 VB 背景,为了我的新工作,我正在转换为 C#.总的来说,我也在努力在 .NET 方面变得更好.我已经看到人们发布的示例中经常使用关键字T".C#中的T"是什么意思?例如:

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()

T 有什么作用?我为什么要使用它?

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

它是 泛型类型参数.它也可以是其他东西,例如:

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()

只有 T 是 Microsoft 使用和鼓励的默认值.

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