Friday, May 11, 2012 1:32 PM
What is Different and when the suitable situation to use all these modifiers?
as far as i know it is encapsulate your information from viewing by the end user. But some say it is hiding information? confusing is this the same? and for connectionString, which is the secure way to encapsulate by protected, private, or sealed internal?
Thank for spending time for this basic question...
Friday, May 11, 2012 1:42 PM
Encapsulating the information is not quite the same as hiding it, but they often go together. Encapsulating the information is simply putting it all into one place (capsule). Often because this is done (and becomes objects contain both data and methods) this allows some or all of that information to be hidden, but it doesn't need to be hidden to be encapsulated (and often isn't).
You can simply do a web search on C# access modifiers to see the definition of each of them, or you can search them individually and likely get some results.
As for your specific example, the structure or architecture of your program will involve much more than the scope and access modifier of a single class or field, and you will need to provide much more information for a meaningful answer to such an example.
Friday, May 11, 2012 1:47 PMProtected internal => only internal types can see or any other class that inherits can see
sealed internal => available only on method overrides, closes the hierarchy, visible only on internal types
sealed private => does not make sense
private => visible only to other members of the class
protected => visible only to derived classes
sealed => close the hierarchy, not possible to override
Friday, May 11, 2012 2:16 PMMatteo, your first statement is wrong. Protected internal means it's available to any class that inherits from the containing class OR any internal classes, rather than requiring a type to be bother internal AND an inheriting type.
Friday, May 11, 2012 2:26 PMSorry, which is the difference from what I said?
A protected internal method is visible only to another internal class (not public) that inherits.
Friday, May 11, 2012 2:51 PM
if a field is protected internal any class that doesn't inherit from that field's class but is in the same assembly can access the field. Any class that inherits from the parent class but is in another assembly can still access the field.
You said that a type must be BOTH in the same assembly AND inheriting from the parent class.
Friday, May 11, 2012 3:07 PM