How many times did you need a property to be read-only for the users of your API, but also you needed that property to be populated by your own data access layer?

It happened to me many times, and I usually solved that problem accessing directly the underlying field changing its visibility from private to internal or protected.

But what if you want to access everything as a property and don't want to hook directly to the field?
You need to be able to specify for the setter a different visibility for the getter.

Here is how:

        private int _id;

        public int Id
            get { return _id; }
            internal set {  _id = value; }

That's a feature of C# I like a lot, and that allows a lot of flexibility.

Just have to remember that the setter visibility modifier must be more restricted than the general one.

UPDATE: This feature is available only with .NET 2.0 (Thank Bill for pointing it out)