我要让存储phones
像一个程序:
将数据存储在数组,对象,结构,列表或类中。 C#
Brand: Samsung
Type: Galaxy S3
Price: 199.95
Ammount: 45
-------------------
Brand: LG
Type: Cookie
Price: 65.00
Ammount: 13
-------------------
etc, etc, etc,
什么是做到这一点的最佳做法?
在php
我应该做的:
$phones = array(
array(
array("Brand" => "Samsung"),
array("Type" => "Galaxy S3"),
array("Price" => 199.95),
array("Ammount" => 45)
),
array(
array("Brand" => "LG"),
array("Type" => "Cookie"),
array("Price" => 65.00),
array("Ammount" => 13)
)
)
这也有可能在C#
,因为我不知道有多少电话在列表中去,和数据类型是不同的:string
,decimal
,int
。 我不知道该用什么,因为你有lists
,structs
,objects
,classes
等等。
在此先感谢!
要积极主动并为其他数据添加字符串(特殊优惠,回扣,html链接,你的名字) – 2014-10-02 08:41:21
@pe:我可以添加数百万其他东西,比如重写'ToString'或'Equals' +'GetHashCode' ,从'string'或..or ..解析。但它只会分散基本的注意力。我认为OP很聪明,可以理解这个概念。 – 2014-10-02 08:43:33
这不是批评,而是对OP的建议。你的答案接近完美(不开玩笑)。 – 2014-10-02 08:45:47