Manas Mohapatra
What are the uses of "Using" keyword in C#?
By Manas Mohapatra in .NET on Jul 10 2015
  • Manas Mohapatra
    Jul, 2015 10

    We can use Using keyword in following ways:1. Generally we use Using keyword when we add any namespace in our class, code-behind files.. Like: Using System.IO;2. Secondly we can use Using keyword when an object need to destroy automatically. It can be used in ADO.NET, Entity Framework, Web Service call. Here system automatically closes/disposes the object. Like: Using(WCFService cc = new WCFService()) {cc.method(); }

    • 4
  • Mahesh Aelakurthi
    Aug, 2015 14

    1) using statement is used to call the Dispose method to destroy an object when it's usage is no more. Ex: using (TextWriter w = File.CreateText("log.txt")) { w.WriteLine("This is line one"); } 2) using keyword is used to call namespaces. Ex: using System.IO;

    • 2
  • Vijay Kumar
    Oct, 2015 10

    We are using "Using" Keyword in C# .Net for including pre-defined classes in .Net Framework.

    • 1
  • Jaipal Reddy
    Sep, 2015 11

    using statement is used to import the namespaces, and to dispose the objects.

    • 1
  • Rajeev Kumar
    Mar, 2023 2

    To allow the normal use of types in a namespace, using System.IO;
    To create an alias for a namespace or a type. This is called a using alias directive.
    using myp = System.Data;
    The using statement ensures that Dispose() is called even if an exception occurs when you are creating objects and calling methods, properties and so on. Dispose() is a method that is present in the IDisposable interface that helps to implement custom Garbage Collection. In other words, if I am doing some database operation (Insert, Update, Delete) but somehow an exception occurs, then here the using statement closes the connection automatically. here’s no need to call the connection Close() method explicitly.

    using (SqlConnection conn = new SqlConnection(connString))

    • 0
  • Kml Surani
    Dec, 2015 21

    Using Keyword to used pre-defined classes

    • 0
  • Rajesh Singh
    Dec, 2015 5

    Using key is used for: 1. To include name spaces 2. To close/dispose object.

    • 0
  • Dhanik Sahni
    Nov, 2015 17

    1. It used for including reference of other dll in your project. 2. It is used to dispose object from memory which is inherited from IDisposible interface.

    • 0
  • Sreekanth Reddy
    Nov, 2015 2

    1.For importing name spaces. 2.For providing the scope of object.

    • 0
  • Ashok Karale
    Oct, 2015 19

    I am sure that till now you get to know what are the uses of 'Using'. Here is the link for what happen when we use 'using'. Hope the best.http://www.codeproject.com/Articles/17106/The-using-Keyword-in-C

    • 0
  • Vamsi Krishna
    Oct, 2015 12

    "Using" key word suing for importing name spaces and dispose the connections like ADO.NET,WEB SERVICES,ENTITY FRAME WORK etc...

    • 0
  • Ahtasham Hassan
    Sep, 2015 10

    keywords are some special words that are used for special purpose. for example if if is a keyword and it has some special functionality in the program

    • 0
  • Sujeet Suman
    Sep, 2015 2

    1. Used to import namespace. 2. Used to dispose object.

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS