How can I access and change elements in this private readonly property?
- by CrimsonX
I'm trying to figure out how I am able to successfully change a "readonly" array. I have this:
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
MyClass myClass = new MyClass();
myClass.Time[5] = 5; // How is this legal?
}
}
public class MyClass
{
private readonly uint[] time;
public IList<uint> Time
{
get { return time; }
}
public MyClass()
{
time = new uint[7];
}
}
}
As I Note above, I would expect that Time[5] would be illegal due to the fact that public IList Time does not have a setter.
Additionally, how can I create an array in the constructor which is read-only and unchangeable outside of this class?