Okay, I've this classes and main. I'm on VS 2010 Ultimate and .NET 4 Client.
internal class tezt
{
private int[] _numeros = new int[5];
public int[] Numeros
{
get { return _numeros; }
}
}
public class tezt2
{
private int[] _numeros = new int[5];
public int[] Numeros
{
get { return _numeros; }
}
}
class tezt3
{
private int[] _numeros = new int[5];
public int[] Numeros
{
get { return _numeros; }
}
}
internal static class Program
{
private static void Main()
{
var arrNums = new tezt();
var arrNums2 = new tezt2();
var arrNums3 = new tezt3();
Console.WriteLine(arrNums.Numeros[0]);
arrNums.Numeros[0] = 5;
Console.WriteLine(arrNums.Numeros[0]);
Console.WriteLine(arrNums2.Numeros[0]);
arrNums2.Numeros[0] = 6;
Console.WriteLine(arrNums2.Numeros[0]);
Console.WriteLine(arrNums3.Numeros[0]);
arrNums3.Numeros[0] = 7;
Console.WriteLine(arrNums3.Numeros[0]);
Console.ReadKey(true);
}
}
What's happening with these lines:
arrNums.Numeros[0] = 5;
arrNums2.Numeros[0] = 6;
arrNums3.Numeros[0] = 7;
Isn't supposed that because the classes from which those objects are derived from haven't a set
parameter, those asignations must not be allowed?
What can be done to avoid that, to restrict that, thad doing thiks like arrNums.Numeros[0] = 5;
throws a error?