regural if / else VS shorthand if / else and type of functions
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: regural if / else VS shorthand if / else and type of functions

  1. #1
    Join Date
    Jun 2009
    Posts
    144

    regural if / else VS shorthand if / else and type of functions

    Hello forum ! i have a question !

    Which one do you recommend as "better" ? or it doesn't hurt ?


    Code:
    private void yes() {
    
        MessageBox.Show("Hah");
    
    }
    
    private void no() {
    
        MessageBox.Show("Hah");
    
    }
    
    if ( x > y ) { yes(); } else {  no(); }



    OR




    Code:
    private bool yes() {
    
        MessageBox.Show("Hah");
        return true;
    
    }
    
    private bool no() {
    
        MessageBox.Show("Hah");
        return true;
    
    }
    
    
    bool answer = ( x > y ) ? yes() : no();

    Thanks !

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,199

    Re: regural if / else VS shorthand if / else and type of functions

    Using the ternary operator (? only makes sense if you need to assign a value.

    It wouldn't be recommended return fake data from methods just to use the ternary operator.

  3. #3
    Join Date
    Jun 2009
    Posts
    144

    Re: regural if / else VS shorthand if / else and type of functions

    thanks !!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center