Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3221876
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:55:36+00:00 2026-05-17T15:55:36+00:00

why make things more complex? why do this: txtNumerator.Text = txtNumerator.Text == ? 0

  • 0

why make things more complex? why do this:

txtNumerator.Text = 
     txtNumerator.Text == "" ? "0" : txtNumerator.Text;

instead of this:

if txtNumerator.Text="" {txtNumerator.Text="0";}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:55:37+00:00Added an answer on May 17, 2026 at 3:55 pm

    Suppose you wanted to pass either zero or txtNumerator.Text to a method M. How would you do that?

    You could say:

    string argument;
    if (txtNumerator.Text == "")
    {
        argument = "0";
    }
    else
    {
        argument = txtNumerator.Text;
    }
    M(argument);
    

    Or you could say

    M(txtNumerator.Text == "" ? "0" : txtNumerator.Text);
    

    The latter is shorter and easier to read.

    The larger point here is that statements are useful for their side effects and expressions are useful for their values. If what you want to do is control which of two side effects happens, then use an “if” statement. If what you want to do is control which value gets chosen from two possibilities, then consider using a conditional expression.

    UPDATE:

    Jenny asks why not just do this?

    if (txtNumerator.Text == "")
    {
        M("0");
    }
    else
    {
        M(txtNumerator.Text);
    }
    

    That’s fine if there’s just one condition to check. But what if there are, say, four? Now there are sixteen possibilities and writing the “if” statement for it gets messy to say the least:

    if (text1.Text == "")
    {
        if (text2.Text == "")
        {
            if (text3.Text == "")
            {
                if (text4.Text == "")
                {
                    M("1", "2", "3", "4");
                }
                else
                {
                    M("1", "2", "3", text4.Text);
                }
            }
            else
            {
                if (text4.Text == "")
                {
                    M("1", "2", text3.Text, "4");
                }
                else
                {
                    M("1", "2", text3.Text, text4.Text);
                }
            }
            ... about fifty more lines of this.
    

    Instead, you can just say:

    M(Text1.Text == "" ? "1" : Text1.Text,
      Text2.Text == "" ? "2" : Text2.Text,
      Text3.Text == "" ? "3" : Text3.Text,
      Text4.Text == "" ? "4" : Text4.Text);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To make things easier when switching between machines (my workstation at the office and
Problem (simplified to make things clearer): 1. there is one statically-linked static.lib that has
I'm trying to make things simpler. Here is my code: If Threading.Monitor.TryEnter(syncRoot) Then Try
I have created some extra functionality on my Linq-to-SQL classes to make things easier
Code that is untestable really annoys me. The following things make oo-code untestable: global
The situation: I have a pieceofcrapuous laptop. One of the things that make it
I frequently make use of Request.QueryString[] variables. In my Page_load I often do things
I've done many web apps where the first thing you do is make a
Make a new AS3 Document in Flash, paste in the following code and run
make is not only useful for building your programming project, but it seems to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.