Difference between using directive vs using statement?



Difference between using directive vs using statement?..

Answer / Anesh Kumar

Using Directives and Using Statements are used in C# to import namespaces, but they have slightly different purposes.nn1. Using Directive:nA using directive imports a namespace at the top of your code file, allowing you to use classes from that namespace without writing the fully qualified name. It creates an alias for the namespace and makes the classes accessible within the scope of the file.nnexample: using System; // imports the System namespacenn2. Using Statement:nA using statement releases the resources acquired by an object when it goes out of scope. This is particularly useful with IDisposable objects, such as those implementing the IDbConnection interface. It creates a disposable object and uses it within the braces, ensuring that the object is disposed of properly after use.nnexample: using (var connection = new SqlConnection(connectionString)) {n // Use the connection object heren}nnIn summary, Using Directives are used for importing namespaces, while Using Statements are used for managing resources.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More ASP.NET Interview Questions

Can you explain the basic use of dataview?

1 Answers  


Difference between abstract factory pattern and factory method pattern in .NET with example.

3 Answers   ACS, IBM, Keane India Ltd,


What is data control in asp.net?

1 Answers  


what is diffgram ?

3 Answers  


If i have 1000 records in dataset, how to do paging?

2 Answers   Mind Tree,


What are Authentication mechanisms in .Net?

6 Answers   Accenture,


what is a virtual class?

1 Answers   Patni,


What is use of <% %> in asp.net?

1 Answers  


How can you register a custom server control to a web page?

1 Answers  


write six HTTP request method?

4 Answers   IBM,


Types of optimization and name a few and how do u do?

1 Answers   Accenture,


What ports must be open for DCOM over a firewall? What is the purpose of Port 135?

1 Answers  


Categories