如何在Silverlight 2中合并列表数组? ................ [英] How to Combine List Array in silverlight 2 ? ................
问题描述
大家好,
我是vino,是Silverlight 2的较新成员.我想在Silverlight 2中合并两个列表数组..请任何一个帮助...
举个简单的例子
这是我的代码. . .
列表数组1
------------
公共类A
{
公共A(字符串名)
{
ANAME = Aname;
}
公用字符串ANAME {get;放; }
}
公共静态列表 alist
列表数组2
-----------
hi all,
I am vino, I am fresher of silverlight 2. I want to combine two list array in silverlight 2 .. please any one help ...
Give simple example
This is my code . . .
List Array 1
------------
public class A
{
public A(string Aname)
{
ANAME = Aname;
}
public string ANAME { get; set; }
}
public static List alist
List Array 2
-----------
public class B
{
public B(string Bname)
{
BName = Bname;
}
public string BName { get; set; }
}
公共静态列表 blist;
如何在单个listarray中组合列表数组A和B以及如何在silverlight 2中使用它.
请指导我
public static List blist;
how to combine the list array A and B in single listarray and how it use in silverlight 2..
please guide me
推荐答案
如果您使用通用List< T> ;,则无法将"A类"与"B类"组合使用.
您可以为"A类"和"B类"构建基类.
If you use a generic List<T>, you cannot combine "class A" with "class B".
You can build a Base class for "class A" and "class B".
public class Base
{
public string Name { get; set; }
}
public class A : Base
{
}
public class B : Base
{
}
List<base> aList = new List<base>;
aList.Add(new A { Name = "From Class A - 1" });
aList.Add(new A { Name = "From Class A - 2" });
List<base blist="new">;
bList.Add(new B { Name = "From Class B - 21" });
bList.Add(new B { Name = "From Class B - 22" });
// Combine aList and bList
List<base> abList = new List<base>;
abList.AddRange(aList);
abList.AddRange(bList);
这篇关于如何在Silverlight 2中合并列表数组? ................的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!