The title of this message is discouraging, isn't it? Nevertheless, you are smart enough to guess what is going to be discussed. At the .NET interview, people often ask the question: “What is the difference between
using directive and
using statement ?” Sometimes additional traps are put before the applicant asking where in the program can you use
using ? The first thing that comes to mind is the use
of the using directive , which is used to define or allow the use of types as namespaces. For example, the following code snippet demonstrates the inclusion of some namespaces using a using
directive .
using System.IO; using System.Text;
Wait a minute This is not all! There is something called “aliasing directive” and you can use it, as shown in the next line of code. This may be an intermediate part of the answer to the question.
using mynamespace = myproject.module;
Now let's return to
the using statement , which sets the scope, beyond which the object is not accessible. Consider the following example:
using(ColorImageFrame imageFrame = e.OpenColorImageFrame()) {
The
imageFrame object
is defined using
a using block . This means that when the execution of the code block is completed, the imageFrame object is no longer required, and it can be
destroyed and deleted. This approach is extremely important for effective memory management.