为什么 C# 不像 C 那样支持局部静态变量? [英] Why doesn't C# support local static variables like C does?
本文介绍了为什么 C# 不像 C 那样支持局部静态变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么 C# 没有像 C 那样的局部静态变量?我想念那个!!
Why doesn't C# have local static variables like C? I miss that!!
推荐答案
您可以使用委托来模拟它...这是我的示例代码:
You can simulate it using a delegate... Here is my sample code:
public Func<int> Increment()
{
int num = 0;
return new Func<int>(() =>
{
return num++;
});
}
你可以这样称呼它:
Func<int> inc = Increment();
inc();
这篇关于为什么 C# 不像 C 那样支持局部静态变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文