【发布时间】:2012-08-07 06:20:06
【问题描述】:
如何创建和填充通用Dictionary<> 它应该由这种类型填充
TKey= string, TValue=Point.
提前谢谢你。
【问题讨论】:
标签: c# .net dictionary
如何创建和填充通用Dictionary<> 它应该由这种类型填充
TKey= string, TValue=Point.
提前谢谢你。
【问题讨论】:
标签: c# .net dictionary
怎么样
Dictionary<string, Point> spdic = new Dictionary<string, Point>();
spdic.Add("mystring", new Point(0,0));
spdic.Add("mystring1", new Point(23,30));
【讨论】:
就这样
Dictionary<string,Point> dic = newDictionary<string,Point> ();
dic.Add("key", new Point(1,1));
【讨论】:
Dictionary<string, Point> myDict = new Dictionary<string, Point>();
myDict.add(myString, myPoint);
【讨论】:
怎么样
Dictionary<string, Point> dict = new Dictionary<string, Point>()
{
{ "string A", new Point(0, 0) }
}
只是为了与其他答案不同并使用对象初始化器
【讨论】:
你可以试试:
Dictionary<string, Point> myDictionary = new Dictionary<string, Point>();
myDictionary.Add("Some String", new Point(x, y));
希望这会有所帮助!
【讨论】:
Dictionary<String, Point> dict = new Dictionary<String, Point>();
dict.Add("abcd", new Point(65,99));
编辑请确保您阅读文档或进行一些搜索,因为您很可能会找到此类问题的答案。以下是您如何使用Add 方法
【讨论】:
您还可以列出包含字符串和点的任何类型的列表并使用
listOfThingsWithStringsAndPoints.ToDictionary(x => x.yourString, x=> x.yourPoint);
只是为了与其他答案不同并使用 ToDictionary
【讨论】: