What I want to do is allow the public incrementation of an integer value within my class, but not allow it to be publicly set explicitly.
I know that I can create a function like this:
void IncrementMyProperty()
but I'd like to allow the user to just do this:
MyClass.Property++;
without allowing this:
MyClass.Property = <SomeInt>;
It's merely for convenience. I'm just wondering if there is any way to do it.
Here's an example:
class MyClass
{
private int _count;
public int Count
{
get { return _count; }
private set { _count = value; }
}
public void AddOne()
{
_count++;
}
}
class Program
{
static void Main()
{
MyClass example;
for (int i = 0; i < 10; i++)
example.Count++;
}
}
Obviously this won't compile. It's just to show what I'd like to do.