當前位置:成語大全網 - 新華字典 - JAVA裏面的dictionary<t,t>怎麽用; 舉個簡單的例子最好,

JAVA裏面的dictionary<t,t>怎麽用; 舉個簡單的例子最好,

我是用C#語言的,字典的基本思路就是,鍵值對!每個鍵值對應壹個值。

這壹段C#代碼妳可以參考壹下:我想對妳有幫助

public class OthelloCast : List<string>

{

// Use a dictionary to contain

// cast names (key) and actor names (value).

public Dictionary<string, string> OthelloDict =

new Dictionary<string, string>();

public OthelloCast()

{

// Add data to the dictionary.

OthelloDict.Add("Bianca", "Gretchen Rivas");

OthelloDict.Add("Brabantio", "Carlos Lacerda");

OthelloDict.Add("Cassio", "Steve Masters");

OthelloDict.Add("Clown", "Michael Ludwig");

OthelloDict.Add("Desdemona", "Catherine Autier Miconi");

OthelloDict.Add("Duke of Venice", "Ken Circeo");

OthelloDict.Add("Emilia", "Eva Valverde");

OthelloDict.Add("Gratiano", "Akos Kozari");

OthelloDict.Add("Iago", "Darius Stasevicius");

OthelloDict.Add("Lodovico", "Fernando Souza");

OthelloDict.Add("Montano", "Jeff Hay");

OthelloDict.Add("Othello", "Marco Tanara");

OthelloDict.Add("Roderigo", "Pedro Ruivo");

// Populate the list with character names.

foreach (KeyValuePair<string, string> kvp in OthelloDict)

{

this.Add(kvp.Key);

}

}