I know that a Struct is a value type and a Class is reference type, however I cannot seem to get around this issue.
I have a class that has a list of a struct:
public class Basket
{
string ID{get; set;}
List<Fruit> fruits{get;set;}
public struct Fruit
{
string Name{get;set;}
bool IsFresh;
}
}
when passing a class instance to another class I want to update one of the Structs' IsFresh property but the code just skips it:
public class Customer
{
public string Name{get;set;}
public Basket Basket{get;set;}
public Customer(string name, Basket basket)
{
this.Name = name;
this.Basket = basket;
}
public ChangeBasket()
{
//CODE THAT IS NOT WORKING
Basket.Fruits[0].IsFresh = false;
}
}
The same referenced class is being modified and the valued structs should be updated.
why is that not working?