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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:16:45+00:00 2026-06-15T07:16:45+00:00

Possible Duplicate: Why do assignment statements return a value? In C# you can use

  • 0

Possible Duplicate:
Why do assignment statements return a value?

In C# you can use a property as both an lrvalue and rvalue at the same time like this :

int n = N = 1;

Here is a complete C# sample :

class Test
{
    static int n;

    static int N
    {
        get { System.Console.WriteLine("get"); return n; }
        set { System.Console.WriteLine("set"); n = value; }
    }

    static void Main()
    {
        int n = N = 1;

        System.Console.WriteLine("{0}/{1}", n, N);
    }
}

You can’t do that in C++/CLI as the resulting type of the assignment expression “N = 1” is void.

EDIT1: here is a C++/CLI sample that shows this :

ref class A
{
    public: static property int N;
};

int main()
{
    int n = A::N = 1;

    System::Console::WriteLine("{0}/{1}", n, A::N);
}

EDIT2: Moreover this is really confusing : what I was expecting was that the getter would be call to assign to n which is not the case at all; n directly receives the right-most value of the expression, i.e. 1 like shown by the generated CIL :

IL_0001:  ldc.i4.1
IL_0002:  dup
IL_0003:  call       void Test::set_N(int32)
IL_0008:  nop
IL_0009:  stloc.0

So what’s the magic behind C# syntax allowing a void-expression to be used as a rvalue ?

Is this special treatment only available for properties or do you know other C# tricks like this ?

EDIT : As pointed out C# assignment rules say that rvalue should ALWAYS be used as the return value of an assignment.

  • 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-15T07:16:47+00:00Added an answer on June 15, 2026 at 7:16 am

    In C#, an assignment is the result of the assignment itself.

    For example:

    string a = null;
    
    if((a = "hello world").Contains("world"))
    {
          Console.WriteLine("It has 'world' word!");
    }
    

    As you see, it’s not about properties, but assignments.

    An statement like this:

    int n = N = 1;
    

    …is equivalent to:

    int n = (N = 1);

    The point of this is (N = 1) has a return value itself: an integer value of 1.

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

Sidebar

Related Questions

Possible Duplicate: Javascript equivalent of PHP's list() In PHP you can do assignment like
Possible Duplicate: JavaScript asynchronous return value / assignment with jQuery I need a prototype
Possible Duplicate: Tuple parameter declaration and assignment oddity In Scala, one can do multiple-variable
Possible Duplicate: Conditional operator assignment with Nullable<value> types? Hi, Why this doesn't work? DateTime?
Possible Duplicate: Conditional operator assignment with Nullable<value> types? in the following code snippet company.ParentID
Possible Duplicate: C# variable initializations vs assignment Just like in the title, could someone
Possible Duplicate: Why use two stacks to make a queue? I got this assignment
Possible Duplicate: Why must the copy assignment operator return a reference/const reference? Operator= overloading
Possible Duplicate: JavaScript OR (||) variable assignment explanation Can someone help explain what this
Possible Duplicate: How to use base class's constructors and assignment operator in C++? class

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.