My understanding is that each new thread in .Net allocates 1MB of stack space. Further my understanding is that value types are stored on the stack rather then the heap...
So my question is this; does this behavior mean that any ValueType variable declarations are limited to 1MB of storage space? That the more ValueTypes you have declared in your current scope the smaller the callstack can effectively be and at some point does this mean that declaring (for the sake of argument) ~260,000 ints would use all your stack space?
A most fruitful answer to this type of question is usually go and test. Others told you that you should not worry about this and they are kind of right. All the articles that are linked are great and well worth reading. In most practical cases, you won't need anywhere near of 1MB of local variables.
But what if you want to know weather you actually can have 1MB of local variables worth? As others pointed out this is implementation details, and the results may vary depending on platform, compiler version, vendor, etc.
Let's test this ourselves and see what is possible and what is not. I'm on an x64 machine with VS2010 and C# 4.0 compiler.
Here is my code:
When I compile and run this code, I am getting the stack overflow exception. This means that at least in some cases you are indeed limited by the stack space. And it does mean that the more local variables you have, the less stack you have left for method calls, recursion, etc.
Once again: these consideration are hardly ever practical. If you are allocating 1MB worth of local variables, you most likely doing something wrong. But in case you are wondering anyway... now you know.