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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:07:42+00:00 2026-05-13T16:07:42+00:00

This is issue about LANGUAGE DESIGN. Please do not answer to the question until

  • 0

This is issue about LANGUAGE DESIGN.

Please do not answer to the question until you read entire post! Thank you.

With all helpers existing in C# (like lambdas, or automatic properties) it is very odd for me that I cannot pass property by a reference. Let’s say I would like to do that:

foo(ref my_class.prop);

I get error so I write instead:

{
   var tmp = my_class.prop;
   foo(tmp);
   my_class.prop = tmp;
}

And now it works. But please notice two things:

  1. it is general template, I didn’t put anywhere type, only “var”, so it applies for all types and number of properties I have to pass

  2. I have to do it over and over again, with no benefit — it is mechanical work

The existing problem actually kills such useful functions as Swap. Swap is normally 3 lines long, but since it takes 2 references, calling it takes 5 lines. Of course it is nonsense and I simply write “swap” by hand each time I would like to call it. But this shows C# prevents reusable code, bad.

THE QUESTION

So — what bad could happen if compiler automatically create temporary variables (as I do by hand), call the function, and assign the values back to properties? Is this any danger in it? I don’t see it so I am curious what do you think why the design of this issue looks like it looks now.

Cheers,

EDIT As 280Z28 gave great examples for beating idea of automatically wrapping ref for properties I still think wrapping properties with temporary variables would be useful. Maybe something like this:

Swap(inout my_class.prop1,inout my_class.prop2);

Otherwise no real Swap for C# 🙁

  • 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-13T16:07:43+00:00Added an answer on May 13, 2026 at 4:07 pm

    There are a lot of assumptions you can make about the meaning and behavior of a ref parameter. For example,

    Case 1:

    int x;
    Interlocked.Increment(ref x);
    

    If you could pass a property by ref to this method, the call would be the same but it would completely defeat the semantics of the method.

    Case 2:

    void WaitForCompletion(ref bool trigger)
    {
        while (!trigger)
            Thread.Sleep(1000);
    }
    

    Summary: A by-ref parameter passes the address of a memory location to the function. An implementation creating a temporary variable in order to “pass a property by reference” would be semantically equivalent to passing by value, which is precisely the behavior that you’re disallowing when you make the parameter a ref one.

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

Sidebar

Ask A Question

Stats

  • Questions 302k
  • Answers 302k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It looks like he's just mapping the mousewheel event to… May 13, 2026 at 8:23 pm
  • Editorial Team
    Editorial Team added an answer You need to use your XmlNamespaceManager as well: XmlNodeList nodeList… May 13, 2026 at 8:23 pm
  • Editorial Team
    Editorial Team added an answer There are sooo many. Lets see (some (very few) from… May 13, 2026 at 8:23 pm

Related Questions

Some time ago I had to address a certain C# design problem when I
I have found Design patterns certification at the Brainbehch. I have heard from people
I have a bunch of scripts - some in perl and some in bash
Even 2 decades ago, it was possible to call code written in one language
Background I am working on a phonetic converter program which converts english text into

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.