如何将此数组转换为c#?
我用PHP制作了以下数组,需要将其转换为c# 我试着做了以下几件事如何将此数组转换为c#?,c#,php,arrays,C#,Php,Arrays,我用PHP制作了以下数组,需要将其转换为c# 我试着做了以下几件事 object[] cards = new Dictionary<string, string> { {"Player", string}, {"Dealer", string} }; object[]cards=新字典 { {“Player”,string}, {“经销商”,字符串} }; 但是它似乎失败了,什么是最好的方法呢?Dictionarycards
object[] cards = new Dictionary<string, string>
{
{"Player", string},
{"Dealer", string}
};
object[]cards=新字典
{
{“Player”,string},
{“经销商”,字符串}
};
但是它似乎失败了,什么是最好的方法呢?Dictionarycards=newdictionary
Dictionary<string, List<string>>cards = new Dictionary<string, List<string>>
{
{"Player", new List<string>()},
{"Dealer", new List<string>()}
};
{
{“玩家”,新列表()},
{“经销商”,新列表()}
};
在C语言中,您可以使用词典(不是数组):
//首先(正如您在评论中提到的),您需要一个Card类
公务舱卡{
公共字符串{get;private set;}
公共字符串值{get;private set;}
公共字符串面{get;private set;}
...
}
//所以你有一个字典解决方案
字典卡片=新字典(){
{“玩家”,新列表()},
{“经销商”,新列表()}
};
或者,如果您想要阵列,您应该将其放在不同的位置(但这是一种组合式设计):
/。。。或阵列解决方案
元组[]卡片=新元组[]{
新元组(“播放器”,新列表()),
新元组(“经销商”,新列表())
};
它不会将卡作为字符串保存,但在“玩家”内部会有不同的数组,每个数组包含一个面键、值键和套装键
Dictionary<string, List<string>>cards = new Dictionary<string, List<string>>
{
{"Player", new List<string>()},
{"Dealer", new List<string>()}
};
// 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>()}
};
// ... 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>())
};