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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:53:34+00:00 2026-06-07T17:53:34+00:00

I think this question was asked many times in C# but my problem is

  • 0

I think this question was asked many times in C# but my problem is maybe more solvable.
I have an object value as a string : myobject.value and I want to store this value in a queue (or anything else) to access it later. Is it possible?

I read a lot of posts saying that it is not possible to store a ref to a string.
I don’t see any solution to store a ref to my string value myobject.value and change it later.

Any Ideas ?

  • 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-07T17:53:37+00:00Added an answer on June 7, 2026 at 5:53 pm

    If you want to store a reference to a string that people can see and share the changes of you will need to wrap it in a class:

    public class Wrapper<T>
    {
        public T Item { get; set; }
    }
    

    Then people use this instead of a string:

    class MyClass
    {
        public Wrapped<string> SharedString { get; set; } 
    }
    
    var c1 = new MyClass();
    var c2 = new MyClass();
    
    var s = new Wrapped<string> { Item = "Hello" };
    
    c1.SharedString = s;
    c2.SharedString = s;
    
    c1.SharedString.Item = "World";
    Console.Writeline(c2.SharedString.Item);
    

    Even though strings are reference types, they are immutable so changes need to the “copied” around. Sharing is this way doesn’t change the immutability, it just centrally holds one copy of a string that everyone is looking at via their reference to Wrapped<string>.

    You can take the Wrapped<T> class further and give it implicit cast support to and from T, for a little syntactic sugar:

    public static implicit operator T(Wrapped<T> wrapper)
    {
        return wrapper.Item;
    }
    
    public static implicit operator Wrapped<T>(T item)
    {
        return new Wrapped<T> { Item = item };
    }
    
    Wrapped<int> i = 2;
    int j = i;
    
    // Careful, this is a re-assignment of s, not a change of s.Item.
    Wrapped<string> s = "Hello"; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think this question has been asked many a times but I've been searching
I know this question has been asked many times, but my problem is a
I know similar questions have been asked many times befor, but I think this
I have seen this question asked many times but none of the answers seem
I see that this question has been asked many times but I think my
I think this is a question that has been asked many times but I
This question has been asked many times before, but they all seem to relate
I know this question was being asked many times but I want to be
I know this question has been asked many times before but I can't find
I know this question has been asked so many times before but I couldn't

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.