Building an object with a [] interface ( not from ILIst) in c#
c#
Solution
You need to write an indexer, like this:
public decimal this[int index] {
get { return data[index]; }
set { data[index] = value; }
}
Problem
I want to pass around some values in an array that will always be a known size. I would like to define a class that represents this array of decimal values which could not be resized, would always have the same number of elements, and supports the [] array notation. In c++ I could do an operator overloading for this - but I can't see how to do it in c# To be clear - the use of the class would be something like: ``` MyValues values = new MyValues; values[3] = 14; values[7] = 10 ``` .... And later ``` decimal aValue = values[2]; ``` Suggestions?