Note that there are some explanatory texts on larger screens.

plurals
  1. POSAFE Pointer to a pointer (well reference to a reference) in C#
    primarykey
    data
    text
    <p>In a C# application I am working on I have a very long identifier as follows:-</p> <pre><code>foo.bar.bwah.blah.whatever.very.very.huge </code></pre> <p>Whenever I to reference this object it's an absolute nightmare, and unfortunately I do need to reference it a lot:-</p> <pre><code>var something = foo.bar.bwah.blah.whatever.very.very.huge.a; var somethingElse = foo.bar.bwah.blah.whatever.very.very.huge.b; foo.bar.bwah.blah.whatever.very.very.huge.c = 12; </code></pre> <p>etc. etc.</p> <p>I want to update this code using a far smaller alias of some kind, the problem is however that I want to change the underlying reference, and have the alias update also <em>without explicitly updating the alias</em>.</p> <p>Currently if I do the following:-</p> <pre><code>foo.bar.bwah.blah.whatever.very.very.huge.a = "hello"; string shorter = foo.bar.bwah.blah.whatever.very.very.huge.a; foo.bar.bwah.blah.whatever.very.very.huge.a = "world"; Console.WriteLine(shorter); </code></pre> <p>It will output "hello". What I want to achieve is something like the following:-</p> <pre><code>foo.bar.bwah.blah.whatever.very.very.huge.a = "hello"; string** shorterPointer = &amp;foo.bar.bwah.blah.whatever.very.very.huge.a; foo.bar.bwah.blah.whatever.very.very.huge.a = "world"; Console.WriteLine(**shorter); </code></pre> <p>Which would output "world" as required.</p> <p>I believe you can achieve something like this using unsafe code in C#, however I <em>cannot</em> do that, I have to use safe code only.</p> <p>Does anybody have any ideas how I might achieve this?</p> <p><strong>Please Note:</strong> This question is not about strings being immutable, I know they are - in fact I assumed they are for the purposes of the question. It might perhaps be simpler if I used some other type... so when I assign "hello" to a then "world" to a, I am <em>instantiating different objects</em> on each occasion, hence my stored reference to a becomes invalid after re-assignment.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload