3 April 2014

Dispose in C#

Dispose() method releases the memory from the variable,
we define the dispose when the variable is in not use,
this variable can be reused again.

Example:

func()
{
sqlcommand cmd=new sqlcommand()
datareader dr;

cmd=new sqlcommand("select* from emp",con)
dr=cmd.executreader;
cmd.dispose();
dr.close();

cmd=new sqlcommand("select* from dept",con)
dr=cmd.executreader;
cmd.dispose();
dr.close();

cmd=new sqlcommand("select* from salgrade",con)
dr=cmd.executreader;
cmd.dispose();
dr.close();

}
cmd.executereader();
cmd.dispose();

No comments:

Post a Comment