2014-03-25 131 views
0

我有以下的數組中的PHP量身定做的,我需要將其轉換爲C#如何將此數組轉換爲c#?

public $Cards = array("Player" => array(), "Bank" => array()); 

我試着做以下

object[] cards = new Dictionary<string, string> 
    { 
     {"Player", string}, 
     {"Dealer", string} 
    }; 

但它似乎是失敗的,什麼是最佳方式這樣做?

回答

1
Dictionary<string, List<string>>cards = new Dictionary<string, List<string>> 
    { 
     {"Player", new List<string>()}, 
     {"Dealer", new List<string>()} 
    }; 
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>()) 
    }; 
+0

它不會持有卡作爲一個字符串,但insi de「播放器」會有不同的數組,每個數組包含一個面部鍵,數值鍵和套裝鍵 – Ali