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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:33:27+00:00 2026-05-24T22:33:27+00:00

I cannot emphasis this more — design reasons . In C++ you could get

  • 0

I cannot emphasis this more — design reasons.

In C++ you could get static element using class (type) reference or object (instance) reference. In C# only the type reference. The more I write in C# the more problems it causes — there are simply moments (again and again) that all I have is object, and in order to to avoid problem with lack of type (and thus access to static element) by creating regular element which passess values back and forth to static element.

One can say, that creating regular (non-static) element within a class to work as proxy for static element is small price, but I don’t get for what actually I am paying. The burden is obvious for me, not critical, but annoying, so what are the benefits?

What are the design reasons, in C# you cannot reference static element of the object (from outside of course)?

Code sample

public class Foo
{
   public static readonly string Name = "name";
}

...

Foo foo = new Foo();

and now consider “Foo.Name” against “foo.Name”;

Example of real case

One of the most used class for me is associative array (my custom class) for enums — AssocEnum. It is like Dictionary but all keys are prefilled. On top of it I have classes like EnumBit (which is AssocEnum) and EnumNames (which is AssocEnum). Unlike Dictionary every instance of give enum has the same Keys property. Which means you could get Keys for AssocEnum type and for its instance.

What bothers me is the fact I have to introduce two properties TypeKeys (for class) and Keys (for instance–which is just a proxy of TypeKeys) just because I cannot call static TypeKeys for instance of AssocEnum.

  • 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-24T22:33:27+00:00Added an answer on May 24, 2026 at 10:33 pm

    IMO the “design reason” here is, in part, related to making intent obvious. Here’s a classic example:

    Thread someOtherThread = GetAnotherThread();
    someOtherThread.Sleep();
    

    now; which thread just went to sleep? Thread.Sleep() is a static method; it only ever impacts the current thread. But our code has suggested (quite incorrectly) that we called a method relating to a specific instance (someOtherThread).

    It would have been entirely possible to design the language to allow it to resolve static methods; that is trivial – so it is absolutely an intentional design choice, rather than a technical limitation.

    As another example:

    Control someControl = GetSomeRandomControl();
    someControl.CheckForIllegalCrossThreadCalls = false;
    

    our code suggests we have made a change to disable cross-thread checks for a specific object; but that is incorrect. We have actually impacted all controls, since CheckForIllegalCrossThreadCalls is a static member.

    Thus:

    Thread.Sleep():
    

    and:

    Control.CheckForIllegalCrossThreadCalls = false;
    

    are far clearer in terms of expressing what they do.

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

Sidebar

Related Questions

Cannot validate this method because the domain mapping for the return type (XXXProxy) could
Cannot get this to work. First time using variables passed into functions. Unchecking radio
cannot get the comments to show in actionscript file when running asdoc.. is this
Cannot get this statement to update the table and am almost certain my problem
Cannot complete the install because one or more required items could not be found.
Cannot dump Stack Overflow XML file into SQL Server 2008. Could you please explain
I cannot understand how this is possible. Please help!! I have an app with
I cannot get a two-way bind in WPF to work. I have a string
I cannot get the internet explorer web developer tool bar to work with a
cannot seem to find a way to get change or focusout to fire for

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.