access-modifiers

When should [assembly: InternalsVisibleTo()] be used?

帅比萌擦擦* 提交于 2019-11-27 05:57:01
问题 I understand that the InternalVisibleTo attribute is used to expose types and methods with the internal access modifier to a specified assembly. I have only ever used this for exposing internal methods to a separate assembly containing a suite of unit tests. I am struggling to think of another scenario when this should be used. Was this attribute introduced specifically to aid unit testing or was there another reason? 回答1: A scenario can be that you have separation of logic between assemblies

Internal vs. Private Access Modifiers

落爺英雄遲暮 提交于 2019-11-27 05:48:25
What is the difference between the internal and private access modifiers in C#? internal is for assembly scope (i.e. only accessible from code in the same .exe or .dll) private is for class scope (i.e. accessible only from code in the same class). Vivek Find an explanation below. You can check this link for more details - http://www.dotnetbull.com/2013/10/public-protected-private-internal-access-modifier-in-c.html Private: - Private members are only accessible within the own type (Own class). Internal: - Internal member are accessible only within the assembly by inheritance (its derived type)

Why is internal protected not more restrictive than internal?

﹥>﹥吖頭↗ 提交于 2019-11-27 05:28:07
问题 I'd like to create an internal auto-property: internal bool IP { get; protected internal set; } I thought it would be possible to make the setter protected or protected internal - but I always get the error accessibility modifier must be more restrictive than the property . Isn't that the case? Private does not help me, here. EDIT: The question is: How do I implement an auto-property with a internal getter and a protected setter? 回答1: It's effectively protected or internal , not and . It's

Protected access modifier in Java

一曲冷凌霜 提交于 2019-11-27 04:33:27
I am having a little trouble understanding the protected access modifier in java (or the design behind it). I thought it meant package access and access through objects that inherit the class containing an abstract member. I wrote the following sample code. I see that the commented out line produces a compilation error if uncommented. Why can I access pro through a Second object in Second but not through a First object in Second? package first; public class First { protected void pro(){ System.out.println("Can see protected method"); } } package first; public class InFirst { public static void

Internal abstract class: how to hide usage outside assembly?

眉间皱痕 提交于 2019-11-27 04:21:39
问题 I have a common assembly/project that has an abstract base class, then several derived classes that I want to make public to other assemblies. I don't want the abstract base class to show up in these other assemblies in Intellisense, so I thought I'd make it internal , but I get this error: Inconsistent accessibility: base class 'Settings' is less accessible than class 'IrcSettings' .... I don't really get this. I am forced to make the abstract Settings class public , and thus visible outside

Any reason to write the “private” keyword in C#?

回眸只為那壹抹淺笑 提交于 2019-11-27 04:16:43
问题 As far as I know, private is the default everywhere in C# (meaning that if I don't write public , protected , internal , etc. it will be private by default). (Please correct me if I am wrong.) So, what's the reason to write that keyword, or why does it even exist for members? For example, when an event handler is auto-generated it looks like this: private void RatTrap_MouseEnter(object sender, CheeseEventArgs e) { } But why does it even write private if that's implied and default? Just so

Why does Typescript use the keyword “export” to make classes and interfaces public?

牧云@^-^@ 提交于 2019-11-27 04:14:08
问题 While dabbling with Typescript I realised my classes within modules (used as namespaces) were not available to other classes unless I wrote the export keyword before them, such as: module some.namespace.here { export class SomeClass{..} } So now I can use the above code like this: var someVar = new some.namespace.here.SomeClass(); However I was just wondering why this keyword is used opposed to just using the public keyword which is used at method level to signify that a method or property

Changing Function Access Mode in Derived Class

╄→гoц情女王★ 提交于 2019-11-27 03:45:29
Consider the following snippet: struct Base { virtual ~Base() {} virtual void Foo() const = 0; // Public }; class Child : public Base { virtual void Foo() const {} // Private }; int main() { Child child; child.Foo(); // Won't work. Foo is private in this context. static_cast<Base&> (child).Foo(); // Okay. Foo is public in this context. } Is this legal C++? "This" being changing the virtual function's access mode in the derived class. Yes, changing the access mode in derived classes is legal. This is similar in form but different in intent to the Non-Virtual Interface idiom. Some rationale is

What does the protected modifier mean? [closed]

为君一笑 提交于 2019-11-27 03:45:28
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I am reading the book The Java Programming Language, 3rd edition. In chapter 3.5 , it illustrates the protected modifier with the following words: More precisely, beyond being accessible within the class itself

Class variables: public access read-only, but private access read/write

天大地大妈咪最大 提交于 2019-11-27 03:33:31
Whoopee, not working on that socket library for the moment. I'm trying to educate myself a little more in C++. With classes, is there a way to make a variable read-only to the public, but read+write when accessed privately? e.g. something like this: class myClass { private: int x; // this could be any type, hypothetically public: void f() { x = 10; // this is OK } } int main() { myClass temp; // I want this, but with private: it's not allowed cout << temp.x << endl; // this is what I want: // this to be allowed temp.f(); // this sets x... // this to be allowed int myint = temp.x; // this NOT