C# 链接4个列表框
首先,我对C语言非常陌生,我试图重新创建一个用Java创建的应用程序 我有4个列表框。每个框将包含xml文件中的值列表 列表框\u年为C# 链接4个列表框,c#,xml,parsing,listbox,hashmap,C#,Xml,Parsing,Listbox,Hashmap,首先,我对C语言非常陌生,我试图重新创建一个用Java创建的应用程序 我有4个列表框。每个框将包含xml文件中的值列表 列表框\u年为。 列表框\u用于。 列表框\u用于的模型。 listBox\u子模型用于 假设我把所有年份都添加到列表框中,没有重复的年份。假设我点击某一年,它将显示该年所有的汽车品牌。然后我点击Make,它会显示该年份下该品牌的车型等 有了Java,我可以使用HashMap来实现这一点,在这里我可以拥有多个相同名称的键,我可以搜索任何一个键,在本例中选择year(年份),获取
。
列表框\u用于
。
列表框\u用于
的模型。
listBox\u子模型用于
假设我把所有年份都添加到列表框中,没有重复的年份。假设我点击某一年,它将显示该年所有的汽车品牌。然后我点击Make,它会显示该年份下该品牌的车型等
有了Java,我可以使用HashMap来实现这一点,在这里我可以拥有多个相同名称的键,我可以搜索任何一个键,在本例中选择year(年份),获取所有以该年份为键的make或值
以下是XML格式
<?xml version="1.0" encoding="utf-8" ?>
<vehicles>
<Manufacturer>
<Make>Subaru</Make>
<Year>2010</Year>
<Model>Impreza</Model>
<Sub-Model>2.0i</Sub-Model>
<Highway>36 MPG highway</Highway>
<City>27 MPG city</City>
<Price>$17,495</Price>
<Description>
Symmetrical All-Wheel Drive.
SUBARU BOXER® engine.
Seven airbags standard.
>Vehicle Dynamics Control (VDC).
</Description>
</Manufacturer>
<Manufacturer>
<Make>Toyota</Make>
<Year>2012</Year>
<Model>Supra</Model>
<Sub-Model>TT</Sub-Model>
<Highway>22 MPG highway</Highway>
<City>19 MPG city</City>
<Price>$48,795</Price>
<Description>
16-inch aluminum-alloy wheels.
6-speaker audio system w/iPod® control.
Bluetooth® hands-free phone and audio.
Available power moonroof.
</Description>
</Manufacturer>
<Manufacturer>
<Make>Subaru</Make>
<Year>2011</Year>
<Model>Impreza</Model>
<Sub-Model>2.0i Limited</Sub-Model>
<Highway>36 MPG highway</Highway>
<City>27 MPG city</City>
<Price>$18,795</Price>
<Description>
16-inch aluminum-alloy wheels.
6-speaker audio system w/iPod® control.
Bluetooth® hands-free phone and audio.
Available power moonroof.
</Description>
</Manufacturer>
<Manufacturer>
<Make>Subaru</Make>
<Year>2011</Year>
<Model>Impreza</Model>
<Sub-Model>2.0i Limited</Sub-Model>
<Highway>36 MPG highway</Highway>
<City>27 MPG city</City>
<Price>$18,795</Price>
<Description>
16-inch aluminum-alloy wheels.
6-speaker audio system w/iPod® control.
Bluetooth® hands-free phone and audio.
Available power moonroof.
</Description>
</Manufacturer>
</vehicles>
斯巴鲁
2010
翼豹
2.0i
每加仑36英里公路
27英里每加仑城市
$17,495
对称全轮驱动。
斯巴鲁BOXER®发动机。
标准配置七个安全气囊。
>车辆动态控制(VDC)。
丰田
2012
上文
TT
每加仑22英里公路
每加仑19英里城市
$48,795
16英寸铝合金车轮。
带iPod®控制的6扬声器音频系统。
Bluetooth®免提电话和音频。
可用的电源在屋顶。
斯巴鲁
2011
翼豹
2.0i有限公司
每加仑36英里公路
27英里每加仑城市
$18,795
16英寸铝合金车轮。
带iPod®控制的6扬声器音频系统。
Bluetooth®免提电话和音频。
可用的电源在屋顶。
斯巴鲁
2011
翼豹
2.0i有限公司
每加仑36英里公路
27英里每加仑城市
$18,795
16英寸铝合金车轮。
带iPod®控制的6扬声器音频系统。
Bluetooth®免提电话和音频。
可用的电源在屋顶。
与java hashmap最接近的类型是字典。因为您需要有多个具有相同键的项,所以我将使用字典
。
以下是您可能需要的一些基本功能:
void AddItem(int key, Item i, Dictionary<int,List<Item>> dict)
{
if (!dict.ContainsKey(key))
{
dict.Add(i,new List<Item>());
}
dict[key].Add(i);
}
List<Item> GetList(int key)
{
if (dict.ContainsKey(key))
{
return dict[key];
}
else
{
return new List<Item>(); // can also be null
}
}
void AddItem(int键,项i,字典dict)
{
如果(!dict.ContainsKey(键))
{
dict.Add(i,新列表());
}
dict[key].添加(i);
}
List GetList(int键)
{
if(dict.ContainsKey(键))
{
返回dict[键];
}
其他的
{
return new List();//也可以为null
}
}
与java hashmap最接近的类型是字典。因为您需要有多个具有相同键的项,所以我将使用字典
。
以下是您可能需要的一些基本功能:
void AddItem(int key, Item i, Dictionary<int,List<Item>> dict)
{
if (!dict.ContainsKey(key))
{
dict.Add(i,new List<Item>());
}
dict[key].Add(i);
}
List<Item> GetList(int key)
{
if (dict.ContainsKey(key))
{
return dict[key];
}
else
{
return new List<Item>(); // can also be null
}
}
void AddItem(int键,项i,字典dict)
{
如果(!dict.ContainsKey(键))
{
dict.Add(i,新列表());
}
dict[key].添加(i);
}
List GetList(int键)
{
if(dict.ContainsKey(键))
{
返回dict[键];
}
其他的
{
return new List();//也可以为null
}
}
您的问题是什么?你在找一本字典吗?
?我不确定这个集合叫什么,但似乎@lcfseth很快就回答了这个问题。你的问题是什么?你在找一本字典吗?
?我不确定这个集合叫什么,但似乎@lcfseth很快就回答了这个问题。非常感谢你,我将尝试一下。我已经有一段时间没上过这个网站了。非常感谢你,我将尝试一下。我已经有一段时间没上这个网站了。