Maximum number of variables in method

后端 未结 2 775
面向向阳花
面向向阳花 2021-01-11 23:21

I was here idle, so I had this curiosity, Someone can tell me what\'s the maximum number of variables per method in C#?

相关标签:
2条回答
  • 2021-01-12 00:06

    I just tried to compile a generated program source with 26*26*26*26 local variables, not method parameters, (they were called @aaaa, @aaab, @aaac and so on), and I hit this limitation:

    error CS0204: Only 65534 locals are allowed

    0 讨论(0)
  • 2021-01-12 00:16

    There is no known limit on count of variables, also because any variable can have different size, but there is a memory limit on execution stack size.

    Quoting Brian:

    The default stack size for a .NET application is 1 MB (default is 256 KB for 32-bit ASP.NET apps and 512 KB for 64-bit ASP.NET apps), but you can change that. For the application you can change the default size by modifying the PE header of the executable. For threads you create, you can use the constructor overload that takes a stack size.

    Stack capacity in C#

    0 讨论(0)
提交回复
热议问题