I want to implement a property that returns a value based on the index it receives. I am not just encapsulating a private array. In fact, the data I will be returning is not stored in any arrays, but instead stored in member objects. This array property will simply be a way to access this data in an indexed way without needing to store it in an indexed way.
According to this article, the following should work:
public double Angles[int i]
{
get { // return a value based on i; }
}
I get the following error, however:
The type or namespace 'i' could not be found (are you missing a using directive or an assembly reference?)
Invalid token ']' in class, struct or interface member declaration
Invalid expression term 'int'
Bad array declarator: To declarate a managed array the rank specifier precedes the variable's identifier. To declare a fixed size buffer field, use the fixed keyword before the field type.
Array size cannot be specified in a variable declaration (try initializing with a 'new' expression)
From those errors, I think it seems that the compiler thinks I am attempting to create an array member. Obviously my syntax is wrong here. Can anybody tell me the correct way to do this?