MEMORYSTREAM IN USING STATEMENT - DO I NEED TO CALL CLOSE()

Jayden Bell

Total Post:110

Points:774
Posted by  Jayden Bell
C# 
C#
 1166  View(s)
Ratings:
Rate this:

When using a memory stream in a using statement do I need to call close? For instance is ms.Close() needed here?

  using (MemoryStream ms = new MemoryStream(byteArray))

    { 

      // stuff

      ms.Close();

    }

  1. Pravesh Singh

    Post:412

    Points:2888
    Re: MemoryStream in Using Statement - Do I need to call close()

    Hi jayden,

    No, you don't need. It will be called by the .Dispose() method which is automatically called:

    using (MemoryStream ms = new MemoryStream(byteArray))

        // stuff

    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!