示例#1
0
        public void D_ClassesCanHavePublicGettersWithPrivateSetters()
        {
            // It is possible to have a property with a public getter and a private setter,
            // so a user of the class can get the value but not set it, although methods of
            // the class can set it.
            // The property declaration has to be public, while the setter is declared private.
            ClassWithPublicGetAndPrivateSet obj = new ClassWithPublicGetAndPrivateSet();

            // So this would be illegal:
            // obj.Area = 20;

            obj.Side = 5;
            Assert.AreEqual(FILL_ME_IN, obj.Side);
            Assert.AreEqual(FILL_ME_IN, obj.Area);
        }
        public void D_ClassesCanHavePublicGettersWithPrivateSetters()
        {
            // It is possible to have a property with a public getter and a private setter,
            // so a user of the class can get the value but not set it, although methods of
            // the class can set it.
            // The property declaration has to be public, while the setter is declared private.
            ClassWithPublicGetAndPrivateSet obj = new ClassWithPublicGetAndPrivateSet();

            // So this would be illegal:
            // obj.Area = 20;

            obj.Side = 5;
            Assert.Equal(FILL_ME_IN, obj.Side);
            Assert.Equal(FILL_ME_IN, obj.Area);
        }