重複の可能性:
子スコープとCS0136
C#変数スコープ
私はかなり長い間C#を使用していますが、このエラーに遭遇したばかりです。
私が以下を持っている場合:
if(true)
{
int x = 0;
}
int x = 0;
次のようなエラーが発生します。A local variable named 'x' cannot be declared in this scope because it would give a different meaning to 'x', which is already used in a child scope to denote something else.
そして私がこれを行う場合:
if(true)
{
int x = 0;
}
x = 0;
次のようなエラーが発生します。The name 'x' does not exist in the current context.
どちらか一方があることは理解できますが、なぜこれらのエラーの両方が存在するのですか?最初のオプションを回避する方法はありますか?とても迷惑だと思います。
ありがとう。