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. General Programming
  3. C#
  4. Arrays

Arrays

Scheduled Pinned Locked Moved C#
data-structures
5 Posts 3 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.
  • B Offline
    B Offline
    Bo Hunter
    wrote on last edited by
    #1

    I am having trouble with this compiling. The compiler says that invalid array initializer. int i1 = 12; byte[][] bs1 = new byte[][(uint)dnsQuestions.Count]; for (int j1 = 0; j1 < dnsQuestions.Count; j1++) { bs1[j1] = ((DnsQuestion)dnsQuestions[j1]).ToByteArray(); i1 += (int)bs1[j1].Length; } byte[][] bs2 = new byte[][(uint)answerResourceRecords.Count]; for (int k1 = 0; k1 < answerResourceRecords.Count; k1++) { bs2[k1] = ((ResourceRecord)answerResourceRecords[k1]).ToByteArray(); i1 += (int)bs2[k1].Length; } byte[][] bs3 = new byte[][(uint)authorityResourceRecords.Count]; for (int i2 = 0; i2 < authorityResourceRecords.Count; i2++) { bs3[i2] = ((ResourceRecord)authorityResourceRecords[i2]).ToByteArray(); i1 += (int)bs3[i2].Length; } byte[][] bs4 = new byte[][(uint)additionalResourceRecords.Count]; for (int j2 = 0; j2 < additionalResourceRecords.Count; j2++) { bs4[j2] = ((ResourceRecord)additionalResourceRecords[j2]).ToByteArray(); i1 += (int)bs4[j2].Length; } byte[] bs5 = new byte[(uint)i1]; BinaryWriter binaryWriter = new BinaryWriter(new MemoryStream(bs5)); try { BigEndian.Write(binaryWriter, identifier); BigEndian.Write(binaryWriter, (ushort)flags.Data); BigEndian.Write(binaryWriter, (ushort)dnsQuestions.Count); BigEndian.Write(binaryWriter, (ushort)answerResourceRecords.Count); BigEndian.Write(binaryWriter, (ushort)authorityResourceRecords.Count); BigEndian.Write(binaryWriter, (ushort)additionalResourceRecords.Count); for (int k2 = 0; k2 < (int)bs1.Length; k2++) { binaryWriter.Write(bs1[k2]); } for (int i3 = 0; i3 < (int)bs2.Length; i3++) { binaryWriter.Write(bs2[i3]); } for (int j3 = 0; j3 < (int)bs3.Length; j3++) { binaryWriter.Write(bs3[j3]); } for (int k3 = 0; k3 < (int)bs4.Length; k3++) { binaryWriter.Write(bs4[k3]);

    S W 2 Replies Last reply
    0
    • B Bo Hunter

      I am having trouble with this compiling. The compiler says that invalid array initializer. int i1 = 12; byte[][] bs1 = new byte[][(uint)dnsQuestions.Count]; for (int j1 = 0; j1 < dnsQuestions.Count; j1++) { bs1[j1] = ((DnsQuestion)dnsQuestions[j1]).ToByteArray(); i1 += (int)bs1[j1].Length; } byte[][] bs2 = new byte[][(uint)answerResourceRecords.Count]; for (int k1 = 0; k1 < answerResourceRecords.Count; k1++) { bs2[k1] = ((ResourceRecord)answerResourceRecords[k1]).ToByteArray(); i1 += (int)bs2[k1].Length; } byte[][] bs3 = new byte[][(uint)authorityResourceRecords.Count]; for (int i2 = 0; i2 < authorityResourceRecords.Count; i2++) { bs3[i2] = ((ResourceRecord)authorityResourceRecords[i2]).ToByteArray(); i1 += (int)bs3[i2].Length; } byte[][] bs4 = new byte[][(uint)additionalResourceRecords.Count]; for (int j2 = 0; j2 < additionalResourceRecords.Count; j2++) { bs4[j2] = ((ResourceRecord)additionalResourceRecords[j2]).ToByteArray(); i1 += (int)bs4[j2].Length; } byte[] bs5 = new byte[(uint)i1]; BinaryWriter binaryWriter = new BinaryWriter(new MemoryStream(bs5)); try { BigEndian.Write(binaryWriter, identifier); BigEndian.Write(binaryWriter, (ushort)flags.Data); BigEndian.Write(binaryWriter, (ushort)dnsQuestions.Count); BigEndian.Write(binaryWriter, (ushort)answerResourceRecords.Count); BigEndian.Write(binaryWriter, (ushort)authorityResourceRecords.Count); BigEndian.Write(binaryWriter, (ushort)additionalResourceRecords.Count); for (int k2 = 0; k2 < (int)bs1.Length; k2++) { binaryWriter.Write(bs1[k2]); } for (int i3 = 0; i3 < (int)bs2.Length; i3++) { binaryWriter.Write(bs2[i3]); } for (int j3 = 0; j3 < (int)bs3.Length; j3++) { binaryWriter.Write(bs3[j3]); } for (int k3 = 0; k3 < (int)bs4.Length; k3++) { binaryWriter.Write(bs4[k3]);

      S Offline
      S Offline
      Stephane Rodriguez
      wrote on last edited by
      #2

      Replace all occurences of [][(uint)dnsQuestions.Count] with [(uint)dnsQuestions.Count][].

      1 Reply Last reply
      0
      • B Bo Hunter

        I am having trouble with this compiling. The compiler says that invalid array initializer. int i1 = 12; byte[][] bs1 = new byte[][(uint)dnsQuestions.Count]; for (int j1 = 0; j1 < dnsQuestions.Count; j1++) { bs1[j1] = ((DnsQuestion)dnsQuestions[j1]).ToByteArray(); i1 += (int)bs1[j1].Length; } byte[][] bs2 = new byte[][(uint)answerResourceRecords.Count]; for (int k1 = 0; k1 < answerResourceRecords.Count; k1++) { bs2[k1] = ((ResourceRecord)answerResourceRecords[k1]).ToByteArray(); i1 += (int)bs2[k1].Length; } byte[][] bs3 = new byte[][(uint)authorityResourceRecords.Count]; for (int i2 = 0; i2 < authorityResourceRecords.Count; i2++) { bs3[i2] = ((ResourceRecord)authorityResourceRecords[i2]).ToByteArray(); i1 += (int)bs3[i2].Length; } byte[][] bs4 = new byte[][(uint)additionalResourceRecords.Count]; for (int j2 = 0; j2 < additionalResourceRecords.Count; j2++) { bs4[j2] = ((ResourceRecord)additionalResourceRecords[j2]).ToByteArray(); i1 += (int)bs4[j2].Length; } byte[] bs5 = new byte[(uint)i1]; BinaryWriter binaryWriter = new BinaryWriter(new MemoryStream(bs5)); try { BigEndian.Write(binaryWriter, identifier); BigEndian.Write(binaryWriter, (ushort)flags.Data); BigEndian.Write(binaryWriter, (ushort)dnsQuestions.Count); BigEndian.Write(binaryWriter, (ushort)answerResourceRecords.Count); BigEndian.Write(binaryWriter, (ushort)authorityResourceRecords.Count); BigEndian.Write(binaryWriter, (ushort)additionalResourceRecords.Count); for (int k2 = 0; k2 < (int)bs1.Length; k2++) { binaryWriter.Write(bs1[k2]); } for (int i3 = 0; i3 < (int)bs2.Length; i3++) { binaryWriter.Write(bs2[i3]); } for (int j3 = 0; j3 < (int)bs3.Length; j3++) { binaryWriter.Write(bs3[j3]); } for (int k3 = 0; k3 < (int)bs4.Length; k3++) { binaryWriter.Write(bs4[k3]);

        W Offline
        W Offline
        Wolfgang Loder
        wrote on last edited by
        #3

        Bo, I can see two mistakes: (1) referring to '7.5.10.2 Array creation expressions' in the C# online reference you cannot instantiate the sub-arrays, because the initial value of the first array is null. But in any case this would be an array of new byte [count] []. You try to create a subarray, where no array is created and initiated: new byte [][count] <- this can never work, because the compiler doesn't know how many sub-arrays (i.e. memory) must be initiated. (2) don't cast to uint, use System.Convert.ToUInt32. Hope this makes your year :cool: Wolfgang

        B 1 Reply Last reply
        0
        • W Wolfgang Loder

          Bo, I can see two mistakes: (1) referring to '7.5.10.2 Array creation expressions' in the C# online reference you cannot instantiate the sub-arrays, because the initial value of the first array is null. But in any case this would be an array of new byte [count] []. You try to create a subarray, where no array is created and initiated: new byte [][count] <- this can never work, because the compiler doesn't know how many sub-arrays (i.e. memory) must be initiated. (2) don't cast to uint, use System.Convert.ToUInt32. Hope this makes your year :cool: Wolfgang

          B Offline
          B Offline
          Bo Hunter
          wrote on last edited by
          #4

          So how do I instantiate this? byte[][] bs1 = new byte[(uint)dnsQuestions.Count][]; for (int j1 = 0; j1 < dnsQuestions.Count; j1++) { bs1[j1] = ((DnsQuestion)dnsQuestions[j1]).ToByteArray(); i1 += (int)bs1[j1].Length; } Then how do I instatiate the other part of the array? byte[][] bs1 = new byte[dnsQuestions.Count][dnsQuestions.Count]; for (int j1 = 0; j1 < dnsQuestions.Count; j1++) { bs1[j1] = ((DnsQuestion)dnsQuestions[j1]).ToByteArray(); i1 += (int)bs1[j1].Length; } Like this and IntelliSense says this is wrong. Thank You Bo Hunter

          B 1 Reply Last reply
          0
          • B Bo Hunter

            So how do I instantiate this? byte[][] bs1 = new byte[(uint)dnsQuestions.Count][]; for (int j1 = 0; j1 < dnsQuestions.Count; j1++) { bs1[j1] = ((DnsQuestion)dnsQuestions[j1]).ToByteArray(); i1 += (int)bs1[j1].Length; } Then how do I instatiate the other part of the array? byte[][] bs1 = new byte[dnsQuestions.Count][dnsQuestions.Count]; for (int j1 = 0; j1 < dnsQuestions.Count; j1++) { bs1[j1] = ((DnsQuestion)dnsQuestions[j1]).ToByteArray(); i1 += (int)bs1[j1].Length; } Like this and IntelliSense says this is wrong. Thank You Bo Hunter

            B Offline
            B Offline
            Bo Hunter
            wrote on last edited by
            #5

            If anyone is willing to take a look at this project I would be greatfull. It is Dns query class library with a test app as well. It runs but I get the Server Faliure message. Thanks Again Bo Hunter

            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