コード例 #1
0
        static void Main(string[] args)
        {
            AccessDemo demo = new AccessDemo();

            // Accesible everywhere
            demo.PublicDemo();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var demo = new AccessDemo();
            var bad  = new BadClass();

            bad.Age  = 150;
            bad._age = 150;
            //bad._ssn;

            demo.PublicDemo();
        }
コード例 #3
0
        private void MakeDemoCalls()
        {
            AccessDemo demo = new AccessDemo();

            // Comes from the same project or assembly
            demo.InternalDemo();

            demo.PublicDemo();

            demo.ProtectedInternalDemo();
        }
コード例 #4
0
        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
        }
コード例 #5
0
        static void Main(string[] args)
        {
            AccessDemo demo = new AccessDemo();

            //demo.

            BadClass bad = new BadClass();

            bad.Age  = 150;
            bad._age = 150;

            demo.PublicDemo();
        }
コード例 #6
0
        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;
        }
コード例 #7
0
        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
        }
コード例 #8
0
        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();
        }
コード例 #9
0
        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.
        }
コード例 #10
0
        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();
        }
コード例 #11
0
        static void Main(string[] args)
        {
            AccessDemo demo = new AccessDemo();

            demo.PublicDemo();
        }
コード例 #12
0
        public void MakeDemoCalls()
        {
            var demo = new AccessDemo();

            demo.InternalDemo();
        }
コード例 #13
0
 private void MakeDemoCalls()
 {
     AccessDemo demo = new AccessDemo();
 }
コード例 #14
0
        public void InstanceOutOfProject()
        {
            AccessDemo ac = new AccessDemo();

            ac.D_Public5();
        }