Using in C# | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Using in C#

What is the difference in using "using" in the library declaration and in the part of the code? for example, using (StreamWriter write = new StreamWriter ("")) { // code }

18th Jan 2019, 6:22 AM
Łukasz Klein
Łukasz Klein - avatar
2 Answers
+ 3
First using is for declaring namespaces and the second using is for dispose everything that created in the bracket after it finished
18th Jan 2019, 10:46 PM
Mahdi (Soroush) Jafari
Mahdi (Soroush) Jafari - avatar
+ 2
This is the same world but it is used for different things. At the first case it is used as derective for more comfortable work with different namespaces. At second case it is used as operator witch allows you to use more convenient syntax for working with IDisposable objects.
18th Jan 2019, 10:06 AM
Earl_Grey
Earl_Grey - avatar