George George

George George

  • NA
  • 778
  • 0

private/public get/set

May 3 2008 8:51 AM

Hello everyone,


New to C#, a simple question which my book does not cover.

If we do not specify the public/private access of get/set, then it is of the same as the public/private access to the property itself, but we can overwrite it.

For example, in the following code, in get method, when we do not specify public/private, it will be automatically the same as the property Abc, which makes get public, but in set, we can overwrite it to make it private?

[Code]
public class MyList
{

    class Foo
    {
        private int _abc;

        public int Abc
        {
            get
            {
                return _abc;
            }
            private set
            {
                _abc = value;
            }
        }

    }

    static void Main()
    {
        Foo f = new Foo();
        return;
    }
}
[/Code]


thanks in advance,
George


Answers (6)