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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:25:52+00:00 2026-05-12T22:25:52+00:00

I wonder if there’s any way something like this would be possible for value

  • 0

I wonder if there’s any way something like this would be possible for value types…

public static class ExtensionMethods {
    public static void SetTo(this Boolean source, params Boolean[] bools) {
        for (int i = 0; i < bools.Length; i++) {
            bools[i] = source;
        }
    }
}

then this would be possible:

Boolean a = true, b, c = true, d = true, e;
b.SetTo(a, c, d, e);

Of course, this does not work because the bools are a value type so they are passed into the function as a value, not as a reference.

Other than wrapping the value types into reference types (by creating another class), is there any way to pass a variable into function by the reference (ref) while using params modifier?

  • 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-12T22:25:53+00:00Added an answer on May 12, 2026 at 10:25 pm

    This is not possible. To explain why, first read my essay on why it is that we optimize deallocation of local variables of value type by putting them on the stack:

    https://web.archive.org/web/20100224071314/http://blogs.msdn.com/ericlippert/archive/2009/05/04/the-stack-is-an-implementation-detail-part-two.aspx

    Now that you understand that, it should be clear why you cannot store a “ref bool” in an array. If you could, then you could have an array which survives longer than the stack variable being referenced. We have two choices: either allow this, and produce programs which crash and die horribly if you get it wrong — this is the choice made by the designers of C. Or, disallow it, and have a system which is less flexible but more safe. We chose the latter.

    But let’s think about this a little deeper. If what you want is to pass around “thing which allows me to set a variable”, we have that. That’s just a delegate:

    static void DoStuff<T>(this T thing, params Action<T>[] actions)
    {
        foreach(var action in actions) action(thing);
    }
    ...
    bool b = whatever;
    b.DoStuff(x=>{q = x;}, x=>{r = x;} );
    

    Make sense?

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

Sidebar

Related Questions

I wonder if there is something like a standalone version of Visual Studio's "Immediate
I wonder if there is a way to set the value of #define in
I wonder if there is a way to either programatically or using a third
I wonder if there's a way to do the following: I have a structure
I wonder if there is a way to create a Custom List in Sharepoint,
i wonder if there is a way to access a control's templatepart from within
I wonder if there is a less verbose way to do Input Verification in
i wonder if there is a way to generate valid GUIDs/UUIDs where the first
I wonder if there is a way to use ungreedy matching in JavaScript? I
i wonder if there is something similar to Sql Profiler for Sql Server Compact

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.