Difference Between write statement with using and direct.

Posted by Harsh_rc under C# on 5/24/2011 | Points: 10 | Views : 851 | Status : [Member] | Replies : 3
can anyone tell me what's exactly difference between those two sentence

using (XmlWriter writer = XmlWriter.Create("employees.xml"))
{
writer.WriteElementString("ID", employee.Id.ToString());
}

==============================================================

XmlWriter writer = XmlWriter.Create("employees.xml")
writer.WriteElementString("ID", employee.Id.ToString());




Responses

Posted by: Ndebata on: 5/24/2011 [Member] Starter | Points: 25

Up
0
Down
Hi

By in case of using the resource is released automatically at the end of using block. the object scope is limited to that bloack only.
Please take a look at this
http://msdn.microsoft.com/en-us/library/yh598w02.aspx
But
in the other case still that object(writer) is there in memory.

Thanks,
Debata

Harsh_rc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nithadeepak on: 5/24/2011 [Member] Bronze | Points: 25

Up
0
Down
Refer this .....

http://www.w3enterprises.com/articles/using.aspx

Thanks,

Nitha Deepak

Harsh_rc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Susanthampy on: 5/24/2011 [Member] [MVP] Bronze | Points: 25

Login to post response