我在PHP中使用以下数组,我需要将其转换为c#
public $Cards = array("Player" => array(), "Bank" => array());
我尝试过以下
object[] cards = new Dictionary<string, string>
{
{"Player", string},
{"Dealer", string}
};
但似乎失败了,这样做的最佳方式是什么?
答案 0 :(得分:1)
Dictionary<string, List<string>>cards = new Dictionary<string, List<string>>
{
{"Player", new List<string>()},
{"Dealer", new List<string>()}
};
答案 1 :(得分:0)
在C#中,您可以使用Dictionaries
(不是数组):
// First (as you've mentioned in the comment) you need a Card class
public class Card {
public String Suit { get; private set; }
public String Value { get; private set; }
public String Face { get; private set; }
...
}
// An so you have a dictionary solution
Dictionary<string, List<Card>> cards = new Dictionary<string, List<Card>>() {
{"Player", new List<Card>()},
{"Dealer", new List<Card>()}
};
或者,如果你想要数组,你应该采用不同的方式(但它是 combersome 设计):
// ... or array solution
Tuple<String, List<Card>>[] cards = new Tuple<String, List<Card>>[] {
new Tuple<String, List<Card>>("Player", new List<Card>()),
new Tuple<String, List<Card>>("Dealer", new List<Card>())
};