C
Chuck Bowling
Maybe I'm doing something wrong or just don't understand the concept, but
i'm having a problem with default properties.
My impression of how a default property should act is this;
MyClass c = new MyClass();
c = "my text";
In the line above, the string is assigned to a field in the class instance.
If I'm understanding correctly, the way to declare a default property in C#
is to use an indexer like so:
public string this[int i]
{
get{return myString; }
set { myString = value; }
}
I tried this and the only way I could make it work was like so;
c[0] = "my new text";
How is this a default property? It looks to me like no more than a crippled
indexer.
i'm having a problem with default properties.
My impression of how a default property should act is this;
MyClass c = new MyClass();
c = "my text";
In the line above, the string is assigned to a field in the class instance.
If I'm understanding correctly, the way to declare a default property in C#
is to use an indexer like so:
public string this[int i]
{
get{return myString; }
set { myString = value; }
}
I tried this and the only way I could make it work was like so;
c[0] = "my new text";
How is this a default property? It looks to me like no more than a crippled
indexer.