T
Tony Johansson
Hello!
Here I have a simple program that is changing the object that is refering by
the car reference. This works.
Now to my question foreach is readonly and I assume that this must mean that
I'm not allowed to change in this example the
reference car that is refering to the car object when I enumerate through
the collection.?
public static void Main()
{
Car[] vector = { new Car(), new Car(), new Car() };
foreach (Car car in vector)
{
car.Year *= 2;
}
}
class Car
{
int year = 1;
public int Year
{
get { return year; }
set { year = value; }
}
}
//Tony
Here I have a simple program that is changing the object that is refering by
the car reference. This works.
Now to my question foreach is readonly and I assume that this must mean that
I'm not allowed to change in this example the
reference car that is refering to the car object when I enumerate through
the collection.?
public static void Main()
{
Car[] vector = { new Car(), new Car(), new Car() };
foreach (Car car in vector)
{
car.Year *= 2;
}
}
class Car
{
int year = 1;
public int Year
{
get { return year; }
set { year = value; }
}
}
//Tony