Have you failed a job interview?
Send us your job interview questions and get correct answers.
What are the advantages of using 'using' keyword in C# and why would you use it?
Experience Level: Junior
- The keyword
usingis used at the top of the .cs file to tell the computer in which namespaces to look for the classes that are referred to from the file.
- In the first example below, the class
OakTablewill be searched for in the namespaces
- In the second example below, the class
OakTableis defined by the fully qualified name that includes the namespace. You can see that the code for creation new instance of class OakTable in the first example is way shorter than the one in the second example. This is the advantage of using the keyword
using. It helps to reduce the code duplication.
Related C# job interview questions
What is an object in C#?C# Junior
What is a class in C#?C# Junior
What is a namespace in C# and what is it good for?C# Junior
What is abstract class and what is it good for?C# Medior
What is covariance and contravariance?.NETASP.NET MVCASP.NET WebAPIASP.NET WebFormsC# Senior