+ 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?

27th Aug 2017, 12:34 AM
Abdulrauf
Abdulrauf - avatar
6 ответов
+ 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
27th Aug 2017, 3:11 AM
aklex
aklex - avatar
0
thank you so much aklex, please give me any practical example
27th Aug 2017, 3:14 AM
Abdulrauf
Abdulrauf - avatar
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. } }
27th Aug 2017, 7:12 AM
sneeze
sneeze - avatar
0
what is releasing resources pertaining to class in c#
27th Aug 2017, 3:26 PM
Abdulrauf
Abdulrauf - avatar
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.
27th Aug 2017, 7:09 PM
sneeze
sneeze - avatar
0
thanks brother it really helpful
28th Aug 2017, 2:22 AM
Abdulrauf
Abdulrauf - avatar