Andrew Ducker (andrewducker) wrote,
Andrew Ducker
andrewducker

I wish C# had a branch and retrieve statement

I want to be able to retrieve a value and then branch on its value, all in one step. For some reason it irks me to have to say:
var blah = GetBlah();
if(blah != null)
{
//Do Stuff With blah
}

I want to say

if((var blah = GetBlah()) != null)
{
//Do stuff with blah
}

I'm not sure why the extra line bothers me - possibly because it's a pattern I keep having to repeat in my code, and any pattern I repeat irks me after a while. That's why computers are there, to stop you having to do the same thing over and over again.



Original post on Dreamwidth - there are comments there.
Subscribe

  • instagram cross-post

    My ladies of the castle. Original is here on instagram. Original post on Dreamwidth - there are comments there.

  • Interesting Links for 30-07-2021

    'A nightmare scenario': how an anti-trans Instagram post led to violence in the streets (tags: transgender LGBT riots USA OhForFucksSake )…

  • instagram cross-post

    Sophia and Kimball play tug. Gideon is very impressed. Original is here on instagram. Original post on Dreamwidth - there are comments…

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

  • 60 comments

  • instagram cross-post

    My ladies of the castle. Original is here on instagram. Original post on Dreamwidth - there are comments there.

  • Interesting Links for 30-07-2021

    'A nightmare scenario': how an anti-trans Instagram post led to violence in the streets (tags: transgender LGBT riots USA OhForFucksSake )…

  • instagram cross-post

    Sophia and Kimball play tug. Gideon is very impressed. Original is here on instagram. Original post on Dreamwidth - there are comments…