what is the significance of "using" keyword in c#?
Anil Kumar Murmu
using is the system keyword which is used for importing the namespace..for example using system.here system is the namespace.for importing any namespace you must need to use the "Using" Keyword
http://en.wikibooks.org/wiki/C_Sharp_Programming/Keywords/using http://www.codeproject.com/Articles/6564/Understanding-the-using-statement-in-C
Using Imports the All the Details of within the Namespaces you can write you were own classes and use it multiple places in your application For Example using system.Data ; means It will Imports the Dataset, DataTable classes with respective Methods,Events and etc Properties
Take one Class Library and Build itnamespace Example {public class sample{public int math(int i,int j){return (i + j);}} }Now you want to Use math(or any thing from the Example NameSpace) method in your forms/ApplicationYou should Add the Reference(from Bin folder of Example classlibrary) and Mention Namespace Name so that It can be Included li//Importing the Example Namespace Classes or any thing from the Namespace using Example;//Region of code can be accessPublic class mathOperations{static void Main(string[] args){//Creating Object for Sample Class sample sa = new sample();//object with Parametarized Methods callingConsole.WriteLine("Adding Two Numbers: " + sa.math(10, 20));Console.ReadLine();}}
using keyword is used to define the scope of object being created. Once code is get executed outside the using block the resource get released from memory
Using keyword will be used when we want to release unmanged resources that have associated with object and occupy unnecessary memory . It will be used like - using(SqlConnection sqlconnection= new SqlConnection(connectionString) ) {}and class Object
Using keyword will be used when we want to release unmanged resources associated with object. It will be used like - using(SqlConnection sqlconnection= new SqlConnection(connectionString) ) {}Here connection object will release connection with database after using block. Actualy compiler convert Using block into try/finally block where unmanged resouce will be released in finally block. Even if exception occured in using block, unmanged resource will be released in finally block.It is actualy callling dispose method of object after completion of using block. We can create multiple objects in using block.
http://msdn.microsoft.com/en/library/yh598w02.aspx http://www.codeproject.com/Articles/6564/Understanding-the-using-statement-in-C