Не уверен, что это то, откуда вы пришли; someOtherObject
не будет доступен вне блока using
; из-за правил определения объема .
using (Stream stream = File.OpenRead(@"c:\test.txt"))
{
var v1 = "Hello"; //object declared here, wont be accessible outside the block
stream.Write(ASCIIEncoding.ASCII.GetBytes("This is a test"), 0, 1024);
} //end of scope of stream object; as well as end of scope of v1 object.
v1 = "World!"; //Error, the object is out of scope!
Ошибка компилятора: «Имя v1 не существует в текущем контексте.»
Даже после этого произойдет ошибка.
{
int x=10;
}
x = 20; //Compiler error: "The name x does not exist in the current context."
См. это и это для получения дополнительной помощи.