Q:

What is the use of ‘using’ statement in C#?

0

What is the use of ‘using’ statement in C#?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

The ‘using’ block is used to obtain a resource and process it and then automatically dispose of when the execution of the block completed.

In simple words, The reason for the using statement is to ensure that the object is disposed of as soon as it goes out of scope, and it doesn’t require explicit code to ensure that this happens.

Example,

using (MyResource myRes = new MyResource())
{
    myRes.DoSomething();
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Interview Questions and Answers,You Need To Know

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
What is the major use of ‘using’ keyword in c#... >>
<< What is the difference between var and dynamic in ...