What are the two uses of a ‘using’ statement in c#?



What are the two uses of a ‘using’ statement in c#?..

Answer / Anmol Ratan Deepanker

"The 'using' statement is used in C# for resource management, specifically for disposing objects that implement the IDisposable interface. It has two main uses:n
1. Creating and initializing an object with its lifetime managed by the using block.nExample:nusing (FileStream fs = new FileStream("myfile.txt", FileMode.Open)) {nt// Your code heren}n
2. Automatically calling the Dispose() method on objects when the 'using' block ends, ensuring that disposable objects are always properly disposed of."

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Sharp Interview Questions

What is eager and lazy loading in c#?

1 Answers  


Explain what are the steps for creating clr trigger?

1 Answers  


In a C# class we have a SortedList member m_addinProjects we want to provide an iterator to allow the consumer of this class access to the items in the collection. Please provide an iterator method for the AnalyzeAddinsDLL class below and an example of how it would be used. namespace AnalyzeAddinsDLL { public class AllAddInProjects { private SortedList<string, AddInProject> m_addinProjects; public AllAddInProjects() { m_addinProjects = new SortedList<string, AddInProject>(); } } }

1 Answers   ABC, WinsIndia,


How to authenticate web service? When you enter the web service url in browser it should ask username and password. After entering the un&pwd we have to show its methods and service description(wsdl).

3 Answers  


Can we write one page in c# and other in vb in one application ?

3 Answers   Keane India Ltd,


What is the difference between IEnumerator and IEnumerable?

1 Answers   QuestPond,


what is lamda expression?

3 Answers  


Is typeof c#?

1 Answers  


What is activator c#?

1 Answers  


About delegates and events?

2 Answers   ADITI,


What are the Types of assemblies that can be created in dotnet

1 Answers  


How you will connect to windows directory in c#?

2 Answers   HP, nTech Solutions,


Categories