General restrictions in C #, T is the same TSomethingElse, right?

I often see:

public interface IFoo<TWidget> where TWidget : ISomethingElse { }

In this case, the twidget is the same as using T, right? I find this surprisingly difficult for Google or to find in the specs. I am 99% sure that T + any other characters are the same as T, but I wanted to be absolutely sure.

+3
source share
4 answers

A generic parameter name can be any valid identifier name.

In most documentation, you really find Twhere you put it TWidget.

From MSDN:

Designate generic type parameters with descriptive names, unless one literal name is fully understood and the descriptive name adds value.

+5

TWidget , , T+. T +, , , , .

+1

, , T.

You will more often see more descriptive names when there are restrictions imposed on a common type, usually indicating that there may be a restriction. It is also useful to have a longer identifier if you have several typical type parameters, so you can easily remember which one is.

+1
source

The Type parameter may be a name, but the standard way to do this is to use T and then go through the alphabet, since more general types are required.

So you may have public interface IFoo<T, U> where T : ISomethingElse { }

But you can just as easily use it public interface IFoo<Banana, Spiggot>. It really doesn't matter.

0
source

All Articles