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. null value?

null value?

Scheduled Pinned Locked Moved C#
tutorialquestion
10 Posts 6 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.
  • D Offline
    D Offline
    dec82
    wrote on last edited by
    #1

    public class Command { public int Number; public int NoOfParameters; } Command[] Querries = new Command[50]; private void button_Click(object sender, EventArgs e) { initialization() Device mydevice = new Device(); int Add = mydevice.FindAddress(); } public int FindAddress() { SendCommand (Querries[0]) } My initialization method already initialize all Querries[i].Number and Querries[i].NoOfParameters. But when the code is run to SendCommand (Querries[0]), the values of Querries[i] is still null? Why is it so, and how to solve it ? Thanks

    S J realJSOPR 3 Replies Last reply
    0
    • D dec82

      public class Command { public int Number; public int NoOfParameters; } Command[] Querries = new Command[50]; private void button_Click(object sender, EventArgs e) { initialization() Device mydevice = new Device(); int Add = mydevice.FindAddress(); } public int FindAddress() { SendCommand (Querries[0]) } My initialization method already initialize all Querries[i].Number and Querries[i].NoOfParameters. But when the code is run to SendCommand (Querries[0]), the values of Querries[i] is still null? Why is it so, and how to solve it ? Thanks

      S Offline
      S Offline
      SeMartens
      wrote on last edited by
      #2

      Hi, how does your initialization()-method look like? Maybe you could post the code, this could help us to find the problem. Regards Sebastian

      It's not a bug, it's a feature! Me in Softwareland.

      1 Reply Last reply
      0
      • D dec82

        public class Command { public int Number; public int NoOfParameters; } Command[] Querries = new Command[50]; private void button_Click(object sender, EventArgs e) { initialization() Device mydevice = new Device(); int Add = mydevice.FindAddress(); } public int FindAddress() { SendCommand (Querries[0]) } My initialization method already initialize all Querries[i].Number and Querries[i].NoOfParameters. But when the code is run to SendCommand (Querries[0]), the values of Querries[i] is still null? Why is it so, and how to solve it ? Thanks

        J Offline
        J Offline
        Jason C Bourne
        wrote on last edited by
        #3

        Can you show the Initialization() method ?

        Jean-Christophe Grégoire

        D 1 Reply Last reply
        0
        • D dec82

          public class Command { public int Number; public int NoOfParameters; } Command[] Querries = new Command[50]; private void button_Click(object sender, EventArgs e) { initialization() Device mydevice = new Device(); int Add = mydevice.FindAddress(); } public int FindAddress() { SendCommand (Querries[0]) } My initialization method already initialize all Querries[i].Number and Querries[i].NoOfParameters. But when the code is run to SendCommand (Querries[0]), the values of Querries[i] is still null? Why is it so, and how to solve it ? Thanks

          realJSOPR Offline
          realJSOPR Offline
          realJSOP
          wrote on last edited by
          #4

          There must be dozens of your classmates that have already asked this question here. Just because you make the space for 50 instances of your object, doesn't at all mean that you've instantiated the object 50 times. For christ's sake, read your freakin' text books.

          "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
          -----
          "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

          D 1 Reply Last reply
          0
          • J Jason C Bourne

            Can you show the Initialization() method ?

            Jean-Christophe Grégoire

            D Offline
            D Offline
            dec82
            wrote on last edited by
            #5

            private void initialization() { Command[] Querries = new HARTCommand[50]; XmlDocument Reader = new XmlDocument(); Reader.Load("Myfile.xml"); XmlNodeList List = Reader.SelectNodes("/Common/Command"); foreach (XmlNode commandnode in List) { int i = int.Parse(commandnode.Attributes["value"].InnerText); int type= int.Parse(commandnode.Attributes["Para"].InnerTect); Querries[i] = new Command(); Querries[i].CommandNumber = i; Querries[i].NoOfParameters= type; } } I run the code ,and the initialization is working fine.

            D 1 Reply Last reply
            0
            • D dec82

              private void initialization() { Command[] Querries = new HARTCommand[50]; XmlDocument Reader = new XmlDocument(); Reader.Load("Myfile.xml"); XmlNodeList List = Reader.SelectNodes("/Common/Command"); foreach (XmlNode commandnode in List) { int i = int.Parse(commandnode.Attributes["value"].InnerText); int type= int.Parse(commandnode.Attributes["Para"].InnerTect); Querries[i] = new Command(); Querries[i].CommandNumber = i; Querries[i].NoOfParameters= type; } } I run the code ,and the initialization is working fine.

              D Offline
              D Offline
              dec82
              wrote on last edited by
              #6

              sorry, corrected one is here private void initialization() { Command[] Querries = new Command[50]; XmlDocument Reader = new XmlDocument(); Reader.Load("Myfile.xml"); XmlNodeList List = Reader.SelectNodes("/Common/Command"); foreach (XmlNode commandnode in List) { int i = int.Parse(commandnode.Attributes["value"].InnerText); int type= int.Parse(commandnode.Attributes["Para"].InnerTect); Querries[i] = new Command(); Querries[i].CommandNumber = i; Querries[i].NoOfParameters= type; } } I run the code ,and the initialization is working fine.

              J 1 Reply Last reply
              0
              • D dec82

                sorry, corrected one is here private void initialization() { Command[] Querries = new Command[50]; XmlDocument Reader = new XmlDocument(); Reader.Load("Myfile.xml"); XmlNodeList List = Reader.SelectNodes("/Common/Command"); foreach (XmlNode commandnode in List) { int i = int.Parse(commandnode.Attributes["value"].InnerText); int type= int.Parse(commandnode.Attributes["Para"].InnerTect); Querries[i] = new Command(); Querries[i].CommandNumber = i; Querries[i].NoOfParameters= type; } } I run the code ,and the initialization is working fine.

                J Offline
                J Offline
                J4amieC
                wrote on last edited by
                #7

                The problem you have is because "Querries" is defined as a class-level property, but you're redefining it as a local variable in the initialization method. This locval copy is the one you're initializing, not the class-level one you go on to try to use.

                D 2 Replies Last reply
                0
                • realJSOPR realJSOP

                  There must be dozens of your classmates that have already asked this question here. Just because you make the space for 50 instances of your object, doesn't at all mean that you've instantiated the object 50 times. For christ's sake, read your freakin' text books.

                  "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                  -----
                  "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

                  D Offline
                  D Offline
                  Dragonfly_Lee
                  wrote on last edited by
                  #8

                  Do not be mad. In fact, the real problem is that the var he defined in Initializer method override the class field. :) Maybe the code is not clear enough.

                  Tan Li I Love KongFu~

                  1 Reply Last reply
                  0
                  • J J4amieC

                    The problem you have is because "Querries" is defined as a class-level property, but you're redefining it as a local variable in the initialization method. This locval copy is the one you're initializing, not the class-level one you go on to try to use.

                    D Offline
                    D Offline
                    dec82
                    wrote on last edited by
                    #9

                    thanks , but Even if i put whole dose of initialization inside button_Click(object sender, EventArgs e), it is still the same ?

                    1 Reply Last reply
                    0
                    • J J4amieC

                      The problem you have is because "Querries" is defined as a class-level property, but you're redefining it as a local variable in the initialization method. This locval copy is the one you're initializing, not the class-level one you go on to try to use.

                      D Offline
                      D Offline
                      dec82
                      wrote on last edited by
                      #10

                      Thanks, ALready solve it :)

                      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