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. The Lounge
  3. You've either had too much or not enough coffee when...

You've either had too much or not enough coffee when...

Scheduled Pinned Locked Moved The Lounge
comquestion
37 Posts 25 Posters 4 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.
  • C Chris Maunder

    public class MyObject
    {
    public Value1 { get; set; }
    public Value2 { get; set; }
    public Value3 { get; set; }

    /// /// Initializes a new instance of the class.
    /// 
    /// The first value.
    /// The second value.
    /// The third value.
    public MyObject(int value1, int value2, int value3)
    {
        Value1 = value1;  
        Value2 = value2;
        Value3 = Value3;
    }
    

    }

    var value = new MyObject(1,2,3);

    Why is MyObject.Value3 always equal to 0? /slaps self repeatedly, and insert appropriate comic[^]

    cheers Chris Maunder

    CPalliniC Offline
    CPalliniC Offline
    CPallini
    wrote on last edited by
    #21

    Unfortunately that happens, and aging doesn't help. Interestingly enough, in spite of 0x01AA remark, g++ doesn't complain about

    class Foo
    {
    int F;
    public:
    Foo(int f){F = F;}
    //...

    But it does complain about (which is, by the way, the construct every sensible C++ developer would have chosen)

    class Foo
    {
    int F;
    public:
    Foo(int f):F(F){}
    //...

    spitting out a sane

    warning: ‘Foo::F’ is initialized with itself

    In testa che avete, signor di Ceprano?

    1 Reply Last reply
    0
    • C Chris Maunder

      public class MyObject
      {
      public Value1 { get; set; }
      public Value2 { get; set; }
      public Value3 { get; set; }

      /// /// Initializes a new instance of the class.
      /// 
      /// The first value.
      /// The second value.
      /// The third value.
      public MyObject(int value1, int value2, int value3)
      {
          Value1 = value1;  
          Value2 = value2;
          Value3 = Value3;
      }
      

      }

      var value = new MyObject(1,2,3);

      Why is MyObject.Value3 always equal to 0? /slaps self repeatedly, and insert appropriate comic[^]

      cheers Chris Maunder

      RaviBeeR Offline
      RaviBeeR Offline
      RaviBee
      wrote on last edited by
      #22

      DWIM vs. DWIS. /ravi

      My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

      1 Reply Last reply
      0
      • C Chris Maunder

        public class MyObject
        {
        public Value1 { get; set; }
        public Value2 { get; set; }
        public Value3 { get; set; }

        /// /// Initializes a new instance of the class.
        /// 
        /// The first value.
        /// The second value.
        /// The third value.
        public MyObject(int value1, int value2, int value3)
        {
            Value1 = value1;  
            Value2 = value2;
            Value3 = Value3;
        }
        

        }

        var value = new MyObject(1,2,3);

        Why is MyObject.Value3 always equal to 0? /slaps self repeatedly, and insert appropriate comic[^]

        cheers Chris Maunder

        S Offline
        S Offline
        swampwiz
        wrote on last edited by
        #23

        I don't even know what language this is, but I will presume Java. :^) You have Value3 being assigned to the value of ... Value3, so nothing happens there. Evidently, it is initialized to the value of 0. Is it a default int when there is no declaration type? :confused:

        C 1 Reply Last reply
        0
        • S swampwiz

          I don't even know what language this is, but I will presume Java. :^) You have Value3 being assigned to the value of ... Value3, so nothing happens there. Evidently, it is initialized to the value of 0. Is it a default int when there is no declaration type? :confused:

          C Offline
          C Offline
          Chris Maunder
          wrote on last edited by
          #24

          C#, and exactly. Stared and stared and stared and debugged and stared and had another coffee then... :doh: C# will warn you if you do "=" instead of "==" but I was surprised it didn't warn about X = X.

          cheers Chris Maunder

          1 Reply Last reply
          0
          • C Chris Maunder

            public class MyObject
            {
            public Value1 { get; set; }
            public Value2 { get; set; }
            public Value3 { get; set; }

            /// /// Initializes a new instance of the class.
            /// 
            /// The first value.
            /// The second value.
            /// The third value.
            public MyObject(int value1, int value2, int value3)
            {
                Value1 = value1;  
                Value2 = value2;
                Value3 = Value3;
            }
            

            }

            var value = new MyObject(1,2,3);

            Why is MyObject.Value3 always equal to 0? /slaps self repeatedly, and insert appropriate comic[^]

            cheers Chris Maunder

            T Offline
            T Offline
            TheGreatAndPowerfulOz
            wrote on last edited by
            #25

            you forgot to put _ in front of your parameter names. :)

            #SupportHeForShe Government can give you nothing but what it takes from somebody else. A government big enough to give you everything you want is big enough to take everything you've got, including your freedom.-Ezra Taft Benson You must accept 1 of 2 basic premises: Either we are alone in the universe or we are not alone. Either way, the implications are staggering!-Wernher von Braun

            1 Reply Last reply
            0
            • C Chris Maunder

              public class MyObject
              {
              public Value1 { get; set; }
              public Value2 { get; set; }
              public Value3 { get; set; }

              /// /// Initializes a new instance of the class.
              /// 
              /// The first value.
              /// The second value.
              /// The third value.
              public MyObject(int value1, int value2, int value3)
              {
                  Value1 = value1;  
                  Value2 = value2;
                  Value3 = Value3;
              }
              

              }

              var value = new MyObject(1,2,3);

              Why is MyObject.Value3 always equal to 0? /slaps self repeatedly, and insert appropriate comic[^]

              cheers Chris Maunder

              R Offline
              R Offline
              Ryan Peden
              wrote on last edited by
              #26

              Looks like you've committed a capital offence!

              1 Reply Last reply
              0
              • C Chris Maunder

                public class MyObject
                {
                public Value1 { get; set; }
                public Value2 { get; set; }
                public Value3 { get; set; }

                /// /// Initializes a new instance of the class.
                /// 
                /// The first value.
                /// The second value.
                /// The third value.
                public MyObject(int value1, int value2, int value3)
                {
                    Value1 = value1;  
                    Value2 = value2;
                    Value3 = Value3;
                }
                

                }

                var value = new MyObject(1,2,3);

                Why is MyObject.Value3 always equal to 0? /slaps self repeatedly, and insert appropriate comic[^]

                cheers Chris Maunder

                R Offline
                R Offline
                Ron Anders
                wrote on last edited by
                #27

                I looked at it and looked at it and didn't see it either.

                1 Reply Last reply
                0
                • C Chris Maunder

                  public class MyObject
                  {
                  public Value1 { get; set; }
                  public Value2 { get; set; }
                  public Value3 { get; set; }

                  /// /// Initializes a new instance of the class.
                  /// 
                  /// The first value.
                  /// The second value.
                  /// The third value.
                  public MyObject(int value1, int value2, int value3)
                  {
                      Value1 = value1;  
                      Value2 = value2;
                      Value3 = Value3;
                  }
                  

                  }

                  var value = new MyObject(1,2,3);

                  Why is MyObject.Value3 always equal to 0? /slaps self repeatedly, and insert appropriate comic[^]

                  cheers Chris Maunder

                  G Offline
                  G Offline
                  GuyThiebaut
                  wrote on last edited by
                  #28

                  I saw it fairly quickly, there again this sort of case is very easy to miss when you are the one who wrote it. It's the reason why rubber ducks or cardboard programmers are so important.

                  “That which can be asserted without evidence, can be dismissed without evidence.”

                  ― Christopher Hitchens

                  1 Reply Last reply
                  0
                  • D DRHuff

                    Chris Maunder wrote:

                    Why is MyObject.Value3 always equal to 0?

                    Because your code is doing what you told it to do - not what you want it to do? (That is usually my problem with my code!)

                    Socialism is the Axe Body Spray of political ideologies: It never does what it claims to do, but people too young to know better keep buying it anyway. (Glenn Reynolds)

                    K Offline
                    K Offline
                    kalberts
                    wrote on last edited by
                    #29

                    The programmer's lament: I really hate this damn machine - I wish that they would sell it. It doesnt't do the thing I want, but only what I tell it! (source unknown)

                    1 Reply Last reply
                    0
                    • raddevusR raddevus

                      Eric Lynch wrote:

                      I'm surprised there were no compiler errors.

                      It is always interesting to me that C# doesn't produce a compiler error for that. But, I guess it figures you know best. :rolleyes: Maybe there's a warning, but we all ignore warnings. :laugh:

                      K Offline
                      K Offline
                      kalberts
                      wrote on last edited by
                      #30

                      I have had a number of cases where Visual Studio suggests that I should make a variable readonly, for reasons somewhat similar to this one (and I have had similar problems spotting it). That is when there is only a single assignment to the one variant of the name - it is not smart enough to detect that I have declared two differently named variables for the same "real world" value, using one name in half of the statements, the ohter one in the other half. I wish it was that smart :-) (I can think of only one time this happened, though.)

                      1 Reply Last reply
                      0
                      • OriginalGriffO OriginalGriff

                        There is no warning, which surprised me - and I have "treat warnings as errors" set by default ...

                        Sent from my Amstrad PC 1640 Never throw anything away, Griff Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

                        H Offline
                        H Offline
                        Herbie Mountjoy
                        wrote on last edited by
                        #31

                        It often issues warnings when there is also an error. Otherwise you're on your own... We're philosophical about power outages here. A.C. come, A.C. go.

                        1 Reply Last reply
                        0
                        • C Chris Maunder

                          public class MyObject
                          {
                          public Value1 { get; set; }
                          public Value2 { get; set; }
                          public Value3 { get; set; }

                          /// /// Initializes a new instance of the class.
                          /// 
                          /// The first value.
                          /// The second value.
                          /// The third value.
                          public MyObject(int value1, int value2, int value3)
                          {
                              Value1 = value1;  
                              Value2 = value2;
                              Value3 = Value3;
                          }
                          

                          }

                          var value = new MyObject(1,2,3);

                          Why is MyObject.Value3 always equal to 0? /slaps self repeatedly, and insert appropriate comic[^]

                          cheers Chris Maunder

                          M Offline
                          M Offline
                          Mark_Wallace
                          wrote on last edited by
                          #32

                          Because it's emulating the English language: I am I You are you He is he... or maybe she... or he could be it! Warning, Will Robinson! In English, this would be picked up earlier -- at the editor level, not compiler.

                          I wanna be a eunuchs developer! Pass me a bread knife!

                          1 Reply Last reply
                          0
                          • realJSOPR realJSOP

                            that's okay, because my sentence is not part of any widely recognized API...

                            ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                            -----
                            You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                            -----
                            When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

                            G Offline
                            G Offline
                            Gary Wheeler
                            wrote on last edited by
                            #33

                            You under-estimate your importance, IJSOP.

                            Software Zen: delete this;

                            1 Reply Last reply
                            0
                            • C Chris Maunder

                              public class MyObject
                              {
                              public Value1 { get; set; }
                              public Value2 { get; set; }
                              public Value3 { get; set; }

                              /// /// Initializes a new instance of the class.
                              /// 
                              /// The first value.
                              /// The second value.
                              /// The third value.
                              public MyObject(int value1, int value2, int value3)
                              {
                                  Value1 = value1;  
                                  Value2 = value2;
                                  Value3 = Value3;
                              }
                              

                              }

                              var value = new MyObject(1,2,3);

                              Why is MyObject.Value3 always equal to 0? /slaps self repeatedly, and insert appropriate comic[^]

                              cheers Chris Maunder

                              H Offline
                              H Offline
                              Hooga Booga
                              wrote on last edited by
                              #34

                              Wouldn't be a problem in VB. :-)

                              Outside of a dog, a book is a man's best friend; inside of a dog, it's too dark to read. -- Groucho Marx

                              1 Reply Last reply
                              0
                              • C Chris Maunder

                                public class MyObject
                                {
                                public Value1 { get; set; }
                                public Value2 { get; set; }
                                public Value3 { get; set; }

                                /// /// Initializes a new instance of the class.
                                /// 
                                /// The first value.
                                /// The second value.
                                /// The third value.
                                public MyObject(int value1, int value2, int value3)
                                {
                                    Value1 = value1;  
                                    Value2 = value2;
                                    Value3 = Value3;
                                }
                                

                                }

                                var value = new MyObject(1,2,3);

                                Why is MyObject.Value3 always equal to 0? /slaps self repeatedly, and insert appropriate comic[^]

                                cheers Chris Maunder

                                S Offline
                                S Offline
                                soulesurfer
                                wrote on last edited by
                                #35

                                You would have found that pretty quickly with JetBrains, e.g.

                                1 Reply Last reply
                                0
                                • C Chris Maunder

                                  public class MyObject
                                  {
                                  public Value1 { get; set; }
                                  public Value2 { get; set; }
                                  public Value3 { get; set; }

                                  /// /// Initializes a new instance of the class.
                                  /// 
                                  /// The first value.
                                  /// The second value.
                                  /// The third value.
                                  public MyObject(int value1, int value2, int value3)
                                  {
                                      Value1 = value1;  
                                      Value2 = value2;
                                      Value3 = Value3;
                                  }
                                  

                                  }

                                  var value = new MyObject(1,2,3);

                                  Why is MyObject.Value3 always equal to 0? /slaps self repeatedly, and insert appropriate comic[^]

                                  cheers Chris Maunder

                                  G Offline
                                  G Offline
                                  Gary Wheeler
                                  wrote on last edited by
                                  #36

                                  Chris Maunder wrote:

                                  /slaps self repeatedly, and insert appropriate comic[^]

                                  Given that I just passed my 28th anniversary in my current position, I have had 3rd and even 4th-generation opportunities for self-slappage. I keep waiting for one of my past selves to show up and say "Look, you senile old git! We did this before, this was the wrong way, you had to fix it, now get it right the first time!"

                                  Software Zen: delete this;

                                  1 Reply Last reply
                                  0
                                  • C Chris Maunder

                                    public class MyObject
                                    {
                                    public Value1 { get; set; }
                                    public Value2 { get; set; }
                                    public Value3 { get; set; }

                                    /// /// Initializes a new instance of the class.
                                    /// 
                                    /// The first value.
                                    /// The second value.
                                    /// The third value.
                                    public MyObject(int value1, int value2, int value3)
                                    {
                                        Value1 = value1;  
                                        Value2 = value2;
                                        Value3 = Value3;
                                    }
                                    

                                    }

                                    var value = new MyObject(1,2,3);

                                    Why is MyObject.Value3 always equal to 0? /slaps self repeatedly, and insert appropriate comic[^]

                                    cheers Chris Maunder

                                    O Offline
                                    O Offline
                                    obermd
                                    wrote on last edited by
                                    #37

                                    The perils of case sensitive languages.

                                    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