Click here to Skip to main content
15,888,239 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Is there any need to use IDisposable in the block of code below. I am availing of using and hash contains the SHA1 of text taken in from the user and inputData is a byte array. I assume the second block of code is correct.

Example 1:
using (SHA1 hash = SHA1.Create())
{
    txtSHA1.Text = GetBytesToString(hash.ComputeHash(inputData));
    ((IDisposable)hash).Dispose();
}

Example 2:
using (SHA1 hash = SHA1.Create())
{
    txtSHA1.Text = GetBytesToString(hash.ComputeHash(inputData));
}
Posted
Updated 15-Sep-12 2:46am
v2
Comments
[no name] 15-Sep-12 9:07am    
2 is correct. 1 is totally unnecessary and redundant.

1 solution

Go with second option, if you are able to use "using" statement means, that object is inherited from IDisposable class, they have written appropriate dispose events.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900