Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. ReDim Preserve data(totalBytesRead + dataBlock) to C#

ReDim Preserve data(totalBytesRead + dataBlock) to C#

Scheduled Pinned Locked Moved ASP.NET
csharp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aref87
    wrote on last edited by
    #1

    hello i can not convert ReDim Preserve data(totalBytesRead + dataBlock) to C#

    G 1 Reply Last reply
    0
    • A aref87

      hello i can not convert ReDim Preserve data(totalBytesRead + dataBlock) to C#

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Use the Array.Resize method. Note that neither ReDim Preserve nor Array.Resize actually does resize the array. A new array is allocated, and the data is copied from the original array. If possible, you should allocate a sufficiently large array from the stast.

      Despite everything, the person most likely to be fooling you next is yourself.

      A 1 Reply Last reply
      0
      • G Guffa

        Use the Array.Resize method. Note that neither ReDim Preserve nor Array.Resize actually does resize the array. A new array is allocated, and the data is copied from the original array. If possible, you should allocate a sufficiently large array from the stast.

        Despite everything, the person most likely to be fooling you next is yourself.

        A Offline
        A Offline
        aref87
        wrote on last edited by
        #3

        hello i used from Array.Resize,but i could not arrange its arguments please help me that how can i arrange its arguments? thanks public byte[] ExtractBytesFromStream(Stream stream, int dataBlock) { int totalBytesRead = 0; byte[] data; try { while (true) { Array.Reverse(data, totalBytesRead, dataBlock);? Array.Resize(data, totalBytesRead + dataBlock);? int bytesRead = stream.Read(data, totalBytesRead, dataBlock); if (bytesRead == 0) { break; // TODO: might not be correct. Was : Exit While } totalBytesRead += bytesRead; } Array.Reverse(data, -1, totalBytesRead); return data; } catch(Exception ex) { MessageBox.Show(ex.Message); return null; } }

        G 1 Reply Last reply
        0
        • A aref87

          hello i used from Array.Resize,but i could not arrange its arguments please help me that how can i arrange its arguments? thanks public byte[] ExtractBytesFromStream(Stream stream, int dataBlock) { int totalBytesRead = 0; byte[] data; try { while (true) { Array.Reverse(data, totalBytesRead, dataBlock);? Array.Resize(data, totalBytesRead + dataBlock);? int bytesRead = stream.Read(data, totalBytesRead, dataBlock); if (bytesRead == 0) { break; // TODO: might not be correct. Was : Exit While } totalBytesRead += bytesRead; } Array.Reverse(data, -1, totalBytesRead); return data; } catch(Exception ex) { MessageBox.Show(ex.Message); return null; } }

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          First of all, you don't even have an array at all. You have to create an array before you can resize it. Why are you reversing the data in the array? If there is a reason to revere any data in the array, you can't reverse data that isn't even in the array yet, and there is no reason to reverse a bunch of zeroes. Also, you can't use -1 as starting index when reversing a part of an array. You have to resize the array to the size of the actual data read before you return the array. Now you are returning an array that is larger than the actual data read, and you don't return how much of the array that contains valid data.

          Despite everything, the person most likely to be fooling you next is yourself.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups