• 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!
Collapse

You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:

  • You are not logged in. If you are already registered, fill in the form below to log in, or follow the "Sign Up" link to register a new account.
  • You may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
  • If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.

Previously on "C# test - no googling"

Collapse

  • KentPhilip
    replied
    Originally posted by AtW View Post
    You need to have your mouth cleaned...
    That won't be possible. You know the listerine dragon clifford, I made him swallow his own fire, and he cooked himself

    Leave a comment:


  • AtW
    replied
    Originally posted by KentPhilip View Post
    The only shorts I'm interested in are served in a small glass or worn by a half-naked lady...
    You need to have your mouth cleaned...

    Leave a comment:


  • Freamon
    replied
    What a stupid design.

    Principle of least astonishment - Wikipedia, the free encyclopedia

    Leave a comment:


  • jamesbrown
    replied
    Originally posted by minestrone View Post
    I am sure that works the same in java although I really can't be arsed opening up an editor and testing it.
    Yep. A shortcut would be z = x += y, no pun intended.

    Leave a comment:


  • KentPhilip
    replied
    The only shorts I'm interested in are served in a small glass or worn by a half-naked lady...

    Leave a comment:


  • mudskipper
    replied
    Originally posted by aussielong View Post
    Maybe the compiler infers the type of "x + y" to be an int since it could overflow a short. Then youd have to cast that explicitly to a short to assign to "z".
    That would make sense if int+int = long as well. But it doesn't.

    Leave a comment:


  • minestrone
    replied
    Originally posted by DimPrawn View Post
    You are close.

    Yes the compiler assigns the number as integers, because there is no + operator on a short! Then of course the implicit conversion of an int to a short fails at compile time.
    I am sure that works the same in java although I really can't be arsed opening up an editor and testing it.

    Leave a comment:


  • SimonMac
    replied
    Have you tried turning it off and on again?

    Leave a comment:


  • VectraMan
    replied
    Originally posted by DimPrawn View Post
    Yes the compiler assigns the number as integers, because there is no + operator on a short! Then of course the implicit conversion of an int to a short fails at compile time.
    That's just plain stoopid.

    It'll work in C. Should have called it Cb obviously.

    Leave a comment:


  • DimPrawn
    replied
    You are close.

    Yes the compiler assigns the number as integers, because there is no + operator on a short! Then of course the implicit conversion of an int to a short fails at compile time.

    Leave a comment:


  • amcdonald
    replied
    Originally posted by DimPrawn View Post
    Why does it try and assign them as integers?
    Can't remember why, when the shorts were declared I assume it implicitly converts them from integers to shorts, but when you try and add the x and y it tries to pass a reference to x and y as integers ?

    Leave a comment:


  • aussielong
    replied
    Originally posted by DimPrawn View Post
    Why does the following not compile?

    Code:
    short x = 2, y = 3;
    short z = x + y; // Compile-time error
    Maybe the compiler infers the type of "x + y" to be an int since it could overflow a short. Then youd have to cast that explicitly to a short to assign to "z".

    Leave a comment:


  • eek
    replied
    y ends up an integer not a short.

    Then the implicit conversion fails as you can't implicitly convert to a short.

    Leave a comment:


  • bless 'em all
    replied
    Originally posted by BrilloPad View Post
    Can I ask Bob?
    He's asking ATW.

    Leave a comment:


  • DimPrawn
    replied
    Originally posted by amcdonald View Post
    Does it try and assign x and y both as integers, without casting them to a short thus throwing an exception ?
    Why does it try and assign them as integers?

    Leave a comment:

Working...
X