The code you post cannot implement a property because you need to pass a parameter (index).
Try to implement that property as an indexer. But an indexer cannot be declared as default member (using DefaultMemberAttribute).
The DefaultMemberAttribute can be applied on class level and refers to properties only,so it does not work on indexer, (stnkyminky solution).
Here are more about the properties and indexers:
A property is a member that provides access to a characteristic of an object or a class.
Examples of properties include the length of a string, the name of a customer, and so on.
Properties are a natural extension of fields-both are named members with associated types, and the syntax for accessing fields and properties is the same.
However, unlike fields, properties do not denote storage locations.
Instead, properties have accessors that specify the statements to be executed when their values are read or written.
Properties thus provide a mechanism for associating actions with the reading and writing of an object's attributes and also they permit such attributes to be computed.
Property declarations are subject to the same rules as method declarations and here is the general format:
Code:
attribute property-modifier type member-name { accessor-declarations }
The "type" of a property declaration specifies the type of the property introduced by the declaration, and the "member-name" specifies the name of the property.
Unless the property is an explicit interface member implementation, the "member-name" is simply an identifier.
For an explicit interface member implementation, the "member-name" consists of an interface-type followed by a "." and an identifier.
The "type" of a property must be at least as accessible as the property itself.
The "accessor-declarations", which must be enclosed in "{" and "}" tokens, declare the accessors of the property.
The accessors specify the executable statements associated with reading and writing the property.
Even though the syntax for accessing a property is the same as that for a field, a property is not classified as a variable.
Thus, it is not possible to pass a property as a ref or out argument.
Example:
Code:
abstract class A
{
int y;
public virtual int X {
get { return 0; }
}
public virtual int Y {
get { return y; }
set { if(y > value) y=value; }
}
public abstract int Z { get; set; }
}
Each accessor declaration consists of the token "get" or "set" followed by an "accessor-body".
For abstract and extern properties, the accessor-body for each accessor specified is simply a semicolonb (see Z property).
For other properties, the accessor-body for each accessor specified is a block which contains the statements to be executed when the corresponding accessor is invoked.
An indexer is a member that enables an object to be indexed in the same way as an array.
Indexers are declared using indexer-declarations:
Code:
attribute indexer-modifiers indexer-declarator { accessor-declarations }
where indexer-declarator has one of the following formats:
Code:
type this [ parameter-list ]
type interface-type . this [ parameter-list ]
Indexers and properties are very similar in concept, but differ in the following ways:
A property is identified by its name, whereas an indexer is identified by its signature.
A property is accessed through a simple-name or a member-access , whereas an indexer element is accessed through an element-access.
A property can be a static member, whereas an indexer is always an instance member.
A get accessor of a property corresponds to a method with no parameters, whereas a get accessor of an indexer corresponds to a method with the same formal parameter list as the indexer.
A set accessor of a property corresponds to a method with a single parameter named value, whereas a set accessor of an indexer corresponds to a method with the same formal parameter list as the indexer, plus an additional parameter named value.
It is a compile-time error for an indexer accessor to declare a local variable with the same name as an indexer parameter.
Example of an indexer with two paramters:
Code:
class Matrix
{
int[,] cells = new int[26,10];
public int this[char c, int column]
{
get {
return cells[c - 'A', column];
}
set {
cells[c - 'A', colm] = value;
}
}
}
-obislavu-