tags:

views:

151

answers:

2

Is there a limit on the amount of generic parameters you can have on a type in .NET? Either hard limit (like 32) or a soft limit (where it somehow effects performance to much, etc.)

What I'm referring to is:

class Foo<T0, T2, T3, T4, etc.> {
}
+9  A: 

From the C# 2.0 language spec

8.16.3 Multiple type parameters Generic type declarations can have any number of type parameters.

Mark
Thank you, much appreciated.
thr
+7  A: 

Anonymous types in C# 3.0 are actually generic, for reasons which I should probably blog about at some point. When we designed anonymous types we realized that of course people could be creating anonymous types with potentially hundreds of fields, so we did a lot of testing of the performance of generics with lots of type parameters.

We didn't find any notable problems.

However, what we consider acceptable, you might not. My advice: try it and see. Write up some benchmarks, execute them, and then you'll be reasoning from empirical data, rather than reasoning from the guesses of random people on the internet who don't know what your user scenarios are or what performance factors are important to you.

Eric Lippert