항상 using
전에 변수를 선언하여 using
안에 할당 할 수 있다고 생각했습니다. 그리고 나서 여전히 변수를 읽을 수있었습니다. 알고 보니 나는 할 수 없습니다 :-)C#에서 사용하고 사용하는 변수 사용하기 및 사용하기
ReadOnlyCollection<string> collection;
using (var archive = new SevenZipArchive(varRarFileName)) {
collection = archive.Volumes;
MessageBox.Show(collection.Count.ToString()); // Output 10
}
MessageBox.Show(collection.Count.ToString()); // output 0
이 using
전체 시험 방법 사용을 중지하지 않고 작업을 할 수있는 방법 :
private ReadOnlyCollection<string> ExtractRar(string varRarFileName, string varDestinationDirectory) {
ReadOnlyCollection<string> collection;
using (var archive = new SevenZipArchive(varRarFileName)) {
collection = new ReadOnlyCollection<string>(archive.Volumes);
MessageBox.Show(collection.Count.ToString()); // output 10
}
MessageBox.Show(collection.Count.ToString()); // output 0
return collection;
}
그게 효과가 :-) – MadBoy
예. 확인 된 문서와 나의 '새로운'이론은이 경우에는 확실히 작동하지 않을 것입니다. 이것은 훨씬 낫다. –