static void Main(string[] args) { AccessDemo demo = new AccessDemo(); // Accesible everywhere demo.PublicDemo(); }
static void Main(string[] args) { var demo = new AccessDemo(); var bad = new BadClass(); bad.Age = 150; bad._age = 150; //bad._ssn; demo.PublicDemo(); }
private void MakeDemoCalls() { AccessDemo demo = new AccessDemo(); // Comes from the same project or assembly demo.InternalDemo(); demo.PublicDemo(); demo.ProtectedInternalDemo(); }
static void Main(string[] args) { // vi kan tilgå private protected metoder så længe de er den samme assembly/projekt AccessDemo demo1 = new AccessDemo(); InheritFromAccessDemo demo2 = new InheritFromAccessDemo(); demo1.PublicDemo(); // MakeDemoCalls(); demo2.PublicDemo }
static void Main(string[] args) { AccessDemo demo = new AccessDemo(); //demo. BadClass bad = new BadClass(); bad.Age = 150; bad._age = 150; demo.PublicDemo(); }
static void Main(string[] args) { AccessDemo demo = new AccessDemo(); demo.PublicDemo(); //will call just the public method BadClass bad = new BadClass(); //bad.creditCardNumber //bad.SSN //bad._ssn bad.Age = 150; bad._age = 150; }
static void Main(string[] args) { AccessDemo demo = new AccessDemo(); // demo.PrivateDemo(); // you can not call a private method from a different class // demo.InternalDemo(); // you can not call a internal method from a different assembly demo.PublicDemo(); // demo.ProtectedInternalDemo(); // outside the assembly and does not inherit }
static void Main(string[] args) { AccessDemo demo = new AccessDemo(); // instance tida bisa akses ==> demo.PrivateProtectedDemo(); demo.ProtectedDemo(); demo.ProtectedInternalDemo(); demo.InternalDemo(); demo.PublicDemo(); // tidak bisa akses ke methode PrivateProtectedDemo(); ProtectedDemo(); ProtectedInternalDemo(); InternalDemo(); PublicDemo(); }
static void Main(string[] args) { AccessDemo demo = new AccessDemo(); // demo. here shows a much reduced list of available options making things much clearer what can and can't be invoked. // PrivateDemo is not visible in this project! // Internal demo is not accessible here either as this is a different project/assembly demo.PublicDemo(); // Public as expected can be accessed here when it's in a different assembly. BadClass bad = new BadClass(); bad.creditCardNumber = "123456"; // This should never be done - information leakage with no protection to the property! Console.WriteLine(bad.SSN); // Good practice as this will show the filtered property - if _ssn was public we could inadvertently expose information that should be private. bad.Age = 150; // Will in effect do nothing anbd be rejected. If we could get to _age then that property loses its protection and validation SayHello(); // Can invoke a private method within the same class. }
public void Demo() { AccessDemo demo = new AccessDemo(); // instance tida bisa akses: demo.PrivateProtectedDemo(); demo.ProtectedDemo(); demo.ProtectedInternalDemo(); demo.InternalDemo(); // method bisa akses melalui instance hanya untuk: demo.PublicDemo(); // tidak bisa akses methode ==> PrivateDemo() PrivateProtectedDemo(); InternalDemo(); // Method bisa diakses : ProtectedDemo(); ProtectedInternalDemo(); PublicDemo(); }
static void Main(string[] args) { AccessDemo demo = new AccessDemo(); demo.PublicDemo(); }