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

  • Home
  • SEARCH
  • 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 9161129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:53:56+00:00 2026-06-17T13:53:56+00:00

From this post (and not only) we got to the point that the ++

  • 0

From this post (and not only) we got to the point that the ++ operator cannot be applied on expressions returning value.
And it’s really obvious that 5++ is better to write as 5 + 1. I just want to summarize the whole thing around the increment/decrement operator. So let’s go through these snippets of code that could be helpful to somebody stuck with the ++ first time at least.

// Literal
int x = 0++; // Error

// Constant
const int Y = 1;
double f = Y++; // error. makes sense, constants are not variables actually.

int z = AddFoo()++; // Error

Summary: ++ works for variables, properties (through a synthetic sugar) and indexers(the same).
Now the interest part – any literal expressions are optimized in CSC and, hence when we write, say

int g = 5 + 1; // This is compiled to 6 in IL as one could expect.
IL_0001: ldc.i4.6 // Pushes the integer value of 6 onto the evaluation stack as an int32.

For 5++ doesn’t mean 5 becomes 6, it could be a shorthand for 5 + 1, like for x++ = x + 1
What’s the real reason behind this restriction?

int p = Foo()++ //? yes you increase the return value of Foo() with 1, what's wrong with that?

Examples of code that can lead to logical issues are appreciated.

One of real-life example could be, perform one more actions than in the array.

for (int i = 0; i < GetCount()++; i++) { }

Maybe the lack of usage opts compiler teams to avoid similar features?
I don’t insist this is a feature we lack of, just want to understand the dark side of this for compiler writers perhaps, though I’m not. But I know c++ allows this when returning a reference in the method. I’m neither a c++ guy(very poor knowledge) just want to get the real gist of the restriction.
Like, is it just because c# guys opted to restrict the ++ over value expressions or there are definite cases leading to unpredictable results?

  • 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-06-17T13:53:57+00:00Added an answer on June 17, 2026 at 1:53 pm

    In order for a feature to be worth supporting, it really needs to be useful. The code you’ve presented is in every case less readable than the alternative, which is just to use the normal binary addition operator. For example:

    for (int i = 0; i < GetCount() + 1; i++) { }
    

    I’m all in favour of the language team preventing you from writing unreadable code when in every case where you could do it, there’s a simpler alternative.

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

Sidebar

Related Questions

So this all stemmed from not wanting to check each POST in a huge
From this post : I would first suggest that you optimize your dependentObservable (a.k.a.
I have learnt from this post that always use <a> tags or <button> tags
Should be an easy one. I thought, from reading this blog post that I
I got this from antoher post: host = .mylocal.com; var reg = new RegExp('^https?://([^.]*'
I often suffer from the problem opposite what's described in this post . That
All are from this post . What does these statement mean: error(nargchk(5, 6, nargin));
This is a separate question stemming from this post: How to use the filename
I need to do the same thing from this post Pop Images like Google
I've seen a plugin for Vim called AutoClose (discovered from this post) which automatically

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.