Можно ли делать возврат из блока using(){}?
Можно ли делать возврат из тела блока using? Будут ли освобождены неуправляемые ресурсы?
Ответы (1 шт):
Автор решения: Sergey Crowley
→ Ссылка
public static StringReader R()
{
string manyLines = @"This is line one
This is line two
Here is line three
The penultimate line is line four
This is the final, fifth line.";
var reader = new StringReader(manyLines);
using (reader)
{
string? item;
do
{
item = reader.ReadLine();
Console.WriteLine(item);
} while (item != null);
}
return reader;
}
Вот банальный пример