Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0cryptography
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 15-Sep-12 2:28am
Edited 15-Sep-12 2:46am
v2
Comments
Wes Aday at 15-Sep-12 9:07am
   
2 is correct. 1 is totally unnecessary and redundant.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Shai Vashdi 1,518
1 Tadit Dash 350
2 Manas Bhardwaj 319
3 OriginalGriff 243
4 Sergey Alexandrovich Kryukov 205
0 Sergey Alexandrovich Kryukov 9,530
1 OriginalGriff 5,716
2 Peter Leow 4,320
3 Maciej Los 3,540
4 Abhinav S 3,373


Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 15 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid