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 7525933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:41:33+00:00 2026-05-30T03:41:33+00:00

In C#, I am trying to shorten some of my return code. What I

  • 0

In C#, I am trying to shorten some of my return code. What I want to do is something like

condition ? return here:return there;

or

condition ?? return here;

I am having some issues though, the compiler says the expression is not valid. Here is an example:

        int i = 1;
        int a = 2;
        i < a ? i++ : a++;

This is not valid. However,

        int i = 1;
        int a = 2;
        int s = i < a ? i++ : a++;

is valid. Must there be assignment to use this shorthand notation? The only way I can think of using this at the moment is:

int acceptReturn = boolCondition ? return toThisPlace() : 0 ;

I would really like that line of code to look more like:

boolCondition ? return toThisPlace():;

Which is not valid but is what I am after.

  • 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-30T03:41:34+00:00Added an answer on May 30, 2026 at 3:41 am

    ? : is not “shorthand” for if/else – it is a specific operator (conditional) with specific semantic rules. Those rules mean it can be used only as an expression, not as a statement.

    Re the return: if you only want to “return if true”, then code it as such:

    if(condition) return [result];
    

    Don’t try and use a conditional operator as something it is not.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to trim and shorten some HTML. I use this code: $(window).bind(load, function()
I need some help. I am trying to shorten a full product name from
I'm just trying to shorten a line of code that assigns HTML::Element->as_trimmed_text from an
we're trying to sort out some conventions for handling dependencies with code checked into
I'm playing around, trying to write some code to use the tr.im APIs to
I'm trying to render some text in Rails with simple_format, but I want to
I'm trying to achieve something like the following in C++: class MyVector; // 3
I'm trying to shorten a wordpress title to just the first word. For a
Trying to figure out how I can do this properly. The print_r looks like
Trying to copy the msdn refernce here doesn't work and gives an error I

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.