What are the key uses of a Static Generic Class in C#? When should they be used? What examples best illustrate their usage?
e.g.
public static class Example<T>
{
public static ...
}
Since you can't define extension methods in them they appear to be somewhat limited in their utility. Web references on the topic are scarce so clearly there aren't a lot of people using them. Here's a couple:-
http://ayende.com/Blog/archive/2005/10/05/StaticGenericClass.aspx
Static Generic Class as Dictionary
Summary of Answers Given
The key issues appear to be "What's the difference between a static generic class with static methods and a non-generic static class with static generic members?"
The decision as to which to use appears to revolve around "Does the class need to store type-specific state internally?"
If there is no need for type-specific internal storage then a static non-generic class with generic static methods appears to be preferable because the calling syntax is nicer and you can define extension methods within it.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…