Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Why doesn’t C# support static method variables?

0
Posted

Why doesn’t C# support static method variables?

0

Q: In C++, it’s possible to write a static method variable, and have a variable that can only be accessed from inside the method. C# doesn’t provide this feature. Why? A: There are two reasons C# doesn’t have this feature. First, it is possible to get nearly the same effect by having a class-level static, and adding method statics would require increased complexity. Second, method level statics are somewhat notorious for causing problems when code is called repeatedly or from multiple threads, and since the definitions are in the methods, it’s harder to find the definitions.

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123