Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should I name my files with generic class definitions?

I'm writing a couple of classes that all have generic type arguments, but I need to overload the classes because I need a different number of arguments in different scenarios. Basically, I have

 public class MyGenericClass<T> { ... }
 public class MyGenericClass<T, K> { ... }
 public class MyGenericClass<T, K, L> { ... }
 // it could go on forever, but it won't...

I want them all in the same namespace, but in one source file per class. What should I name the files? Is there a best practice?

like image 700
Tomas Aschan Avatar asked Apr 09 '10 23:04

Tomas Aschan


People also ask

What is generic class with example?

A Generic class simply means that the items or functions in that class can be generalized with the parameter(example T) to specify that we can add any type as a parameter in place of T like Integer, Character, String, Double or any other user-defined type.

What is the generic class type called?

Generic Classes These classes are known as parameterized classes or parameterized types because they accept one or more parameters.

What are generic classes used for?

In a nutshell, generics enable types (classes and interfaces) to be parameters when defining classes, interfaces and methods. Much like the more familiar formal parameters used in method declarations, type parameters provide a way for you to re-use the same code with different inputs.


1 Answers

I've seen people use

MyGenericClass`1, MyGenericClass`2 or MyGenericClass`3

(the number is the number of Generic Parameters).

I think that's what you get as a TypeName when you call .ToString on the class.

like image 95
Michael Stum Avatar answered Oct 05 '22 08:10

Michael Stum