+ 1
What is Dispose method of streamReader Class in c#
please give me answers of this question in easy way with example, I am fully confused what is this?
6 Respostas
+ 4
In C# the dispose method is for releasing resources pertaining to class that are unmanaged. You call dispose when you are done using that class. You can also use the using keyword for the class, and it will automatically dispose the class for you when it goes out of scope
0
thank you so much aklex, please give me any practical example
0
https://www.dotnetperls.com/streamreader
List<string> list = new List<string>();
using (StreamReader reader = new StreamReader("file.txt"))
{
string line;
while ((line = reader.ReadLine()) != null)
{
list.Add(line); // Add to list.
Console.WriteLine(line); // Write to console.
}
}
0
what is releasing resources pertaining to class in c#
0
The garbage collector checks every now and then if there are objects that are now longer is use and disposes those objects.
In c# this goes automatically. You do not need to worry about releasing the memory of a object. The c# garbage collector does it for you.
But you can help the garbage collector a bit. Especially when your objects connect to source outside of the c# enviroment like files and databases. By using the using statement.
using
{
}
This tells the garbage collector that the object at "}" the object is out of scope and can be discarded.
0
thanks brother it really helpful