Why and how does C# allow accessing private variables outside the class itself when it’s within the same containing class?

See section 3.5.1 of the C# language specification. The relevant text is this: Private, which is selected by including a private modifier in the member declaration. The intuitive meaning of private is “access limited to the containing type”. Note that the modifier is relevant to the type, not the instance. And then further in section … Read more

mapping private property entity framework code first [duplicate]

Here’s a convention you can use in EF 6+ to map selected non-public properties (just add the [Column] attribute to a property). In your case, you’d change TypeId to: [Column] private int TypeId { get; set; } In your DbContext.OnModelCreating, you’ll need to register the convention: protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Conventions.Add(new NonPublicColumnAttributeConvention()); } … Read more

Define Private field Members and Inheritance in JAVASCRIPT module pattern

No. Privateness in JavaScript can only be done by scoping (and exporting from them: closures). Those functions that need to access the private variables (and functions), called privileged methods need to be defined inside the constructor. Those methods that don’t (which only interact with public properties or other methods) should be defined on the prototype … Read more