你好我有,因爲在Java中,我用來做這在Java中訪問從另一個類C#
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;
}
}
麻煩學習C#的對象字段或屬性的總價()方法是用Java編寫的示例我如何使用它來訪問另一個類中的對象的值。我怎樣才能實現在C#一樣的東西,這是我的代碼
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
}
}
我不知道我的問題是明確的,但基本上我想知道的是我怎麼能達到獲取或一組,如果我的對象是一個類的實際值?
'公共雙總金額=> product.Price *量;'或舊的語法:'公共雙總金額{{返回product.Price *量; }}' – Xiaoy312