Hi I'm having trouble learning c# because in Java I was used to do this in Java
public class Product
{
private double price;
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
public class Item
{
private int quantity;
private Product product;
public double totalAmount()
{
return product.getPrice() * quantity;
}
}
The totalAmount() method is an example with Java of how I use to access an value of an object in another class. How can I achieve the same thing in c#, this is my code
public class Product
{
private double price;
public double Price { get => price; set => price = value; }
}
public class Item
{
private int quantity;
private Product product;
public double totalAmount()
{
//How to use a get here
}
}
I don't know if my question is clear but basically what I want to know is how can I achieve a get or a set if my object is an actual value of one class?
public double TotalAmount => product.Price * quantity;or in old syntax:public double TotalAmount { get { return product.Price * quantity; } }