作为一个练习,我正在尝试将它从 C# 翻译成 vb.net,但是这件作品没有运气,
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public string Category { get; set; }
public decimal Price { get; set; }
}
Product[] products = new Product[]
{ new Product { Id = 1, Name = "Tomato Soup", Category = "Groceries", Price = 1 },
new Product { Id = 2, Name = "Yo-yo", Category = "Toys", Price = 3.75M },
new Product { Id = 3, Name = "Hammer", Category = "Hardware", Price = 16.99M }
};
我试过了
Public class Product
Public Property Id As Integer
Public Property Name As String
Public Property Category As String
Public Property price As Decimal
End Class
Dim products() As Product = { _
new Product (Id = 1, Name = "Tomato Soup", Category = "Groceries", Price = 1 ), _
new Product ( Id = 2, Name = "Yo-yo", Category = "Toys", Price = 3.75M ), _
new Product (Id = 3, Name = "Hammer", Category = "Hardware", Price = 16.99M ) }
我已经看到使用列表而不是数组的建议,所以我将尝试这样做,但想知道我在这里缺少什么。