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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:56:15+00:00 2026-05-10T20:56:15+00:00

In a C# application I am working on I have a very long identifier

  • 0

In a C# application I am working on I have a very long identifier as follows:-

foo.bar.bwah.blah.whatever.very.very.huge 

Whenever I to reference this object it’s an absolute nightmare, and unfortunately I do need to reference it a lot:-

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; 

etc. etc.

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 without explicitly updating the alias.

Currently if I do the following:-

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); 

It will output ‘hello’. What I want to achieve is something like the following:-

foo.bar.bwah.blah.whatever.very.very.huge.a = 'hello'; string** shorterPointer = &foo.bar.bwah.blah.whatever.very.very.huge.a; foo.bar.bwah.blah.whatever.very.very.huge.a = 'world'; Console.WriteLine(**shorter); 

Which would output ‘world’ as required.

I believe you can achieve something like this using unsafe code in C#, however I cannot do that, I have to use safe code only.

Does anybody have any ideas how I might achieve this?

Please Note: 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 instantiating different objects on each occasion, hence my stored reference to a becomes invalid after re-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. 2026-05-10T20:56:15+00:00Added an answer on May 10, 2026 at 8:56 pm

    One way out is to use one or a pair of lambdas.

    For example:

    Func<string> getter = () => blah_de_blah; Action<string> setter = x => blah_de_blah = x; 

    Now, you can use getter and setter to read and write the long identifier.

    However, since your dots are member accessors, the easiest way of going about it is to take a reference to the immediate parent, like so:

    var myHuge = foo.bar.bwah.blah.whatever.very.very.huge; // now access myHuge.a everywhere 

    This is good practice in any case, as a long dotted expression like this is a violation of the Law of Demeter, which inhibits the flexibility of the codebase – it requires too much information in too many places.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Actually, I think append operator is the preferred term. This… May 11, 2026 at 12:19 pm
  • added an answer Session doesn't sound like a winner, won't scale with lots… May 11, 2026 at 12:19 pm
  • added an answer I haven't updated the question, because in the last several… May 11, 2026 at 12:19 pm

Related Questions

At the moment I am working on a project admin application in C# 3.5
I am working on a ASP.net application written in C# with Sql Server 2000
I have a free standing set of files not affiliated with any C# project
I am currently working on an iPhone 2.1 application. I am new to Objective

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.