• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Today's fascinating C# quiz

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    #11
    Originally posted by AtW View Post
    Yes.

    But it's not the answer you'd like.

    The answer is ...


    ... those who write such a piss poor ambiguous code that creates dangerous dependencies on order in which vars are initialised should be fired.

    Happy now?
    He's right you know - Smartass, zealous OO fanatics shouldn't be allowed near OO code, as they are the very people who end up abusing the privilege and confusing everyone.

    Leave OO to us old timers, who can be relied on use it in moderation and not over-egg the pudding!
    Work in the public sector? Read the IR35 FAQ here

    Comment


      #12
      Originally posted by VectraMan View Post
      None of it is executed. It's just a declaration.
      You might want to check assembly view mate

      Comment


        #13
        Nah, the answer these days is WGAS?
        All us techy types are BAs these days, so leave it to the Bobs to figure out; in which case the answer will probably be: whatever you want it to be.

        Comment


          #14
          Originally posted by alluvial View Post
          Nah, the answer these days is WGAS?
          All us techy types are BAs these days, so leave it to the Bobs to figure out; in which case the answer will probably be: whatever you want it to be.
          Personally I would like to know who derives a single class from a base class and thought that using a base class was a good idea.....

          And that is why I like to still be able to code. So I can do code reviews and toss the truly tulip code back at the original developers.
          merely at clientco for the entertainment

          Comment


            #15
            Originally posted by VectraMan View Post
            None of it is executed. It's just a declaration.


            Good answer.

            Comment


              #16
              Code:
              public class Base
              {
              int x = 1; // Point A
              public Base (int x)
              {
              ... // Point B
              }
              }
              public class Derived : Base
              {
              int y = 1; // Point C
              public Derived (int x)
              : base (x + 1) // Point D
              {
              ... // Point E
              }
              }

              C,D,A,B,E

              is the order anyway.

              Hope you all enjoyed, more C# fun next week.

              Comment


                #17
                Originally posted by DimPrawn View Post
                C,D,A,B,E
                Does that mean Base() is called with an unititialised number because D is executed before A?

                I'd have thought ACDBE.
                Will work inside IR35. Or for food.

                Comment


                  #18
                  Originally posted by VectraMan View Post
                  Does that mean Base() is called with an unititialised number because D is executed before A?

                  I'd have thought ACDBE.
                  This exampled assumes you are creating an instance of the derived class.

                  1st y is initialized to 1, that's because fields are initialized before constructors are called.

                  Then then call to the base class constructor is made. So point D.

                  Then as before, fields are initialized before constructors, so point A (x = 1).

                  Then the base class constructor body B and finally the body of the derived constructor E, because base class constructor bodies execute before derived class constructor bodies.

                  With C#, it's never as you think it is.

                  Comment


                    #19
                    I'm a contractor in business.
                    I maximise my profits,so youse can all eat a big fat one, with your c malarkey


                    (\__/)
                    (>'.'<)
                    ("")("") Born to Drink. Forced to Work

                    Comment


                      #20
                      Originally posted by DimPrawn View Post
                      This exampled assumes you are creating an instance of the derived class.

                      1st y is initialized to 1, that's because fields are initialized before constructors are called.

                      Then then call to the base class constructor is made. So point D.

                      Then as before, fields are initialized before constructors, so point A (x = 1).

                      Then the base class constructor body B and finally the body of the derived constructor E, because base class constructor bodies execute before derived class constructor bodies.

                      With C#, it's never as you think it is.
                      Have you thought of changing your name to "Dull Prawn".

                      For f$@@s sake. Have you got no life?

                      Who gives a sh1t about this stuff? What are you trying to prove? That you are clever? Who f€¥¥£g cares man. Can't you come up with something original that adds value to the world?

                      You're better than this.

                      Comment

                      Working...
                      X