corey
corey
CC#
Created by corey on 5/12/2023 in #help
❔ Can you modify fields in a struct?
I understand, thanks!
16 replies
CC#
Created by corey on 5/12/2023 in #help
❔ Can you modify fields in a struct?
so if I use a class instead of a struct, Game game = games[i]; will not return a copy?
16 replies
CC#
Created by corey on 5/12/2023 in #help
❔ Can you modify fields in a struct?
ohhhhh right, makes sense. im too used to how it works in java. only using structs cause we haven't got up to classes yet. thank you!
16 replies
CC#
Created by corey on 5/12/2023 in #help
❔ Can you modify fields in a struct?
I added
public void IncrementQuantityInCart()
{
quantityInCart = quantityInCart + 1;
Console.WriteLine(quantityInCart);
}
public void IncrementQuantityInCart()
{
quantityInCart = quantityInCart + 1;
Console.WriteLine(quantityInCart);
}
into the strruct but still doesnt work
16 replies
CC#
Created by corey on 5/12/2023 in #help
❔ Can you modify fields in a struct?
I create the game object as:
Game game = new Game()
{
gameId = int.Parse(data[0]),
platform = data[1],
rating = data[2],
type = data[3],
quantity = int.Parse(data[4]),
price = double.Parse(data[5]),
title = data[6],
quantityInCart = 0
};
games.Add(game);
Game game = new Game()
{
gameId = int.Parse(data[0]),
platform = data[1],
rating = data[2],
type = data[3],
quantity = int.Parse(data[4]),
price = double.Parse(data[5]),
title = data[6],
quantityInCart = 0
};
games.Add(game);
16 replies