空作用域与匿名动作委托

时间:2019-06-17 13:21:16

标签: c#

我不想问哪种方法更好,所以我想问一下使用匿名动作委托与使用空作用域来封装变量声明是否会对性能产生影响?另外,在某些情况下,一个会比另一个更有利吗?

选项1:

async

选项2:

for (i = 0; i < limit; i++)
{
    // do stuff
}

// empty scope so I don't use a variable declared in enclosing scope above
{
    int i = 0;
    foreach (object thisObject in MyObjects)
    {
        // do stuff
        i++
        if (i >= something)
        {
            break;
            // not doing anything else so this will exit the empty scope
        }
    }
}

此外,如果您认为这里有气味,请告诉我。

0 个答案:

没有答案
相关问题