Why is there no "external" access modifier?

Maybe I'm missing something but shouldn't C# have an external access modifier for methods? Ie an modifier that make an method public but only for other classes, ie the the method cannot be called by the class itself?

Wouldn't that be useful for things like public methods that do locking to ensure that the lock isn't reentred from within the class?

There's no need for it. Access control is used to restrict access to members from untrusted client code.

Remember that in OOP, a class represents an autonomous, self-contained unit of code and is implicitly assumed to be self-consistent.

If you can't trust the code in your own class not to cause reentrancy then what can you trust? It's impractical to guard against every possible eventuality with language features; sometimes it's just up to you as a developer to make sure your own code works :)

Why is There No Socialism In the United States: Werner Sombart , Tackling this debate head-on, Robin Archer puts forward a new explanation for why there is no American labor party-an explanation that suggests that much of� PORTLAND, Ore. — After two months of protests, dozens of arrests and an increased presence of federal officers in downtown Portland, many KGW viewers have contacted us, asking why there isn't a

Interface methods with explicit implementation are probably the closest thing to what you want. Of course, a class could still call them on itself if it casts this to the interface type.

Why is there no International Theory?, Why Is There No Consensus About Reopening Schools? by Kim Tingley. Here's what we know: With too many variables and too few studies, schools lack the tools� The federal $600-weekly unemployment benefit that was authorized as part of the CARES Act coronavirus relief package in March officially ends today. Although benefits effectively ended last week

I think it wouldn't be useful. There is no paradigm that defines any need for it.

In your example: even if there is the external keyword how do you ensure that the lock cannot be re-entered externally without releasing it?

There are contracts between classes, and the class is always in a contract with itself. I think no keyword can help to avoid such programming mistakes. In this particular example, the class should implement the locking properly depending on its level of usage.

News: Why Is There No Consensus About (The New York Times , Thanks to Mack Weldon for sponsoring this episode. To get 20% off your first order, visit http Duration: 11:45 Posted: Oct 26, 2019 Beginning with tonight’s June 30 episode, viewers watching the show from home should note that there will be no audience present behind the judges. While it is a necessary change (large

this is my pen on Typescript.

Maybe this can be useful for anybody to describe the problem wich can be solved by external access modifier

codepen

class ExternalUser {

  private static _time: number = 0;
  position: {x: number, y: number} = {x: 0, y: 0};

  constructor () {
    setInterval(this.bind(this.tick), 100);
  }

  external static set time(val: number) {
    ExternalUser._time = val;
  }

  static get time(): number {
    return ExternalUser._time;
  }

  private tick() {
    let someRandomThing = Math.random() > 0.95;
    if (someRandomThing) {
      ExternalUser.time += 100;// throws error, because set time is external
    }
    this.position={x: 10 * ExternalUser.time, y: ExternalUser.time * 10};
  }
}

Why Is There No E in the A-F Grading Scale?, In particular, there is no drug recommended specifically for the management of tinnitus. Whilst some of the currently available interventions are� The U.S. has no high-speed trains, aside from sections of Amtrak's Acela line in the Northeast Corridor. Watch to find out why.

Why Is There No Cure for Tinnitus?, A new study shows that 60% of the world's wars have lasted for at least a decade. From Afghanistan to Libya, Syria to Congo DRC, has endless� Why there are no distinct terms between a variable and an unknown quantity in literature? Ask Question Asked today. Active today. Viewed 29 times 2 $\begingroup$

Wars without end: why is there no peaceful solution to so much , But the reality is there are no true generic insulins available — defined as chemically identical to brand-name products and with the same� The lessons learned will help scientists create a vaccine for Sars-CoV-2, but there is still an awful lot to learn about the virus. A chief concern is that coronaviruses do not tend to trigger

Why Is There No Generic Insulin?, Why is There No NATO in Asia? Collective Identity, Regionalism, and the Origins of Multilateralism - Volume 56 Issue 3 - Christopher Hemmer, Peter J. In the SUPER GT season opener at Fuji Speedway last month, Toyota’s ‘new’ GT500 team scored a podium first time out – but scratch beneath the surface and there’s not much new about

Comments
  • There is an extern keyword, but its not used for what you describe. msdn.microsoft.com/en-us/library/e59b22c5%28v=vs.80%29.aspx
  • This is only useful to programmers with multiple personality disorder. If you want methods un-accessible by a class, put them in a different class. By design, a oop class should have access and control over the methods and data contained within the class.
  • Actually, I think the other answers are better. I was going to go on a rant about how you ought not need this behavior, but the lure of coming up with a clever solution was too great.
  • Progress and the IProgress interface is a really good example of a good use of this. IProgress<T>.Report is a private member, so anyone creating a Progress<T> class does not see the Report() method, but all consumers who take in the IProgress<T> interface can call the Report() method to call back.
  • I dunno, I think syntax that clarifies intent of code and ensures certain behavior is generally a good thing, that's why we have things like the readonly keyword. There's no reason why a class couldn't have a "contract" with itself