4 ms·
In .Net/C# this is done with IDisposable and the using statement which works quite well. Ex: using (var sr = new StreamReader(filename)) { txt = sr.R
by SigmundA 4y ago
In .Net/C# this is done with IDisposable and the using statement which works quite well.
Ex:
using (var sr = new StreamReader(filename))
{
txt = sr.ReadToEnd();
}
https://learn.microsoft.com/en-us/dotnet/api/system.idisposable?view=net-7.0 https://learn.microsoft.com/en-us/dotnet/api/system.idisposa...
- pjmlp 4y agoModern C# version, using var sr = new StreamReader(filename); txt = sr.ReadToEnd(); And for the "what about forgeting to call using?", https://devblogs.microsoft.com/dotnet/infer-interprocedural-memory-safety-analysis-for-c/ https://devblogs.microsoft.com/dotnet/infer-interprocedural-... No different from using all those static analisers in C and C++ to keep the code free of memory corruptions and UB issues.
- MaxBarraclough 4y agoDoes it behave identically without the braces?