0

What is TProperty in c#?

I saw a code like this:

public abstract class Myclass<T, TProperty> : .... 

I know that T is a generic type for the type we are passing. Is TProperty also the same as T.

khcha22
  • 79
  • 1
  • 5
  • 3
    `TProperty` is just another type parameter, just like `T`. – Patrick Hofman May 21 '15 at 15:20
  • Could you show some more of the code? –  May 21 '15 at 15:21
  • It simply has 2 generic type parameters. One is called T and the other is called TProperty. – Dennis_E May 21 '15 at 15:21
  • Yes it's just another generic type. You can name them whatever you want. T, K, TKey, etc. are just conventions. – PiotrWolkowski May 21 '15 at 15:22
  • Note that you can name a generic type anything you want. The conventions is to start the name with an upper case T and a lot of code that only has one generic parameter just uses T. But if you have more than one they need unique names. – juharr May 21 '15 at 15:22
  • 2
    I think it is a legitimate question. My apology for all of the downvoters. –  May 21 '15 at 15:23
  • So, TProperty can be anything like M,N et.c.. Right? Should it be only a property member in a class – khcha22 May 21 '15 at 15:24
  • Yes it can be anything. There are some naming conventions to keep it clear: http://programmers.stackexchange.com/a/94552 – PiotrWolkowski May 21 '15 at 15:26

3 Answers3

1

Anything inside the <> is a generic type indicator. It's name does not make any difference to the compiler, but it should be meaningful for code readability.
Just like in Dictionary<TKey, TValue>.
Of course it has to be unique to it's scope, inclusive of variable names in that scope.
Note that type indicators are not variables, but the Do collide with variable names (Thank you Aravol for your comment on that).

Zohar Peled
  • 79,642
  • 10
  • 69
  • 121
  • Interesting, never knew but it looks like Generic Parameter names DO collide with variable names, unlike normal types. Just be wary that the name isn't technically a "variable" - and this can be important to usage in Reflection! – David May 21 '15 at 15:33
1

TProperty is a second generic parameter.

  • Like object parameters on methods, the names have to be unique to distinguish them
  • Generics can have more than one parameter
  • By convention, generic parameter names either are or start with a capital "T".
David
  • 10,458
  • 1
  • 28
  • 40
0

From the description of the class you provide:

public abstract class Myclass<T, TProperty> : .... 

It appears the person who created the class intends for an object (T) and an object property (TProperty) to be supplied whenever creating the class.

A best guess would be something like this:

var mine = new Myclass<Generic.List, String>();

It is hard to tell without any more code or the context of how the code is used, though.