Using ステートメントと {} Scope 修飾子を使用する場合、その外側の値をどのように取得しますか? これは、手続き型コードの無名関数のように感じますが、そうではありません。
using (SqlConnection m_DBCon = new Something())
{
int x = 1;
}
{
int y = 3;
}
x; // not found
y; // not found
Using ステートメントと {} Scope 修飾子を使用する場合、その外側の値をどのように取得しますか? これは、手続き型コードの無名関数のように感じますが、そうではありません。
using (SqlConnection m_DBCon = new Something())
{
int x = 1;
}
{
int y = 3;
}
x; // not found
y; // not found
using ブロックの前に必要な変数を宣言し、内部で割り当てます。
int x;
using (SqlConnection m_DBCon = new Something())
{
x = 1;
}
// x == 1
以下を使用します。
int x, y;
using (SqlConnection m_DBCon = new Something())
{
x = 1;
}
{
y = 3;
}
// x = 1, y = 3
using ブロックの前に変数を宣言し、内部でアクセスします。
int x;
int y;
using (SqlConnection m_DBCon = new Something())
{
x = 1;
}
{
y = 3;
}
x;
y;
変数のスコープを変更するだけです。(そしておそらくそれらも初期化します。)
int x = 0;
int y = 0;
using (SqlConnection m_DBCon = new Something())
{
x = 1;
}
{
y = 3;
}