如何将 List<string> 转换为 IEnumerable<ServiceReference.datatable> C# Silverlight WCF RIA Services LINQ to SQL
How to convert a List<string> to an IEnumerable<ServiceReference.datatable> C# Silverlight WCF RIA Services LINQ to SQL
我一直在尝试将列表转换为 IEnumerable<>,将我的服务引用与我的 table 一起传递到我的数据库中。一开始我需要将 IEnumerable 转换为字符串列表,以便我可以使用 Sort() 函数,但现在我试图将它转换回 IEnumerable,这样我就可以将它用作我的组合框的 Itemsource。任何想法如何做到这一点?
我使用 Silverlight 5 和 WCF RIA 服务,使用 LINQ to SQL,并使用 C# 语言。
代码在我到目前为止的代码下方,但我在网上找到的任何东西都无法转换回 IEnumerable。
ServiceReference1.LoginInfo 是我的 table 在我的数据库中。
IEnumerable<ServiceReference1.LoginInfo> list = e.Result as IEnumerable<ServiceReference1.LoginInfo>;
string comboname;
List<string> items = new List<string>();
for (int i = 0; i < list.Count(); i++)
{
comboname = list.ElementAt(i).UserName;
items.Add(comboname);
items.Sort();
}
//This is where i need something to convert the list<string> items to the IEnumerable<ServiceReference1.LoginInfo> list
//set the itemsource
RegisterPanel_CarrierComboBox.ItemsSource = list;
我再次尝试将此字符串列表转换为可枚举的主要原因是因为我需要能够将其设置为我的项目源,以使我的组合框正常工作。一旦这一切都设置好了,我就可以解决下一个问题,即为什么当我切换到另一个堆栈面板时我的组合框不会清除。
任何和所有答案都会有所帮助。谢谢
根据我从您的代码中了解到的情况,您只想按用户名对 LoginInfo 列表进行排序。
正确吗?
IEnumerable<LoginInfo> list = ...
list = list.OrderBy(t => t.username).ToList();
我一直在尝试将列表转换为 IEnumerable<>,将我的服务引用与我的 table 一起传递到我的数据库中。一开始我需要将 IEnumerable 转换为字符串列表,以便我可以使用 Sort() 函数,但现在我试图将它转换回 IEnumerable,这样我就可以将它用作我的组合框的 Itemsource。任何想法如何做到这一点?
我使用 Silverlight 5 和 WCF RIA 服务,使用 LINQ to SQL,并使用 C# 语言。
代码在我到目前为止的代码下方,但我在网上找到的任何东西都无法转换回 IEnumerable。
ServiceReference1.LoginInfo 是我的 table 在我的数据库中。
IEnumerable<ServiceReference1.LoginInfo> list = e.Result as IEnumerable<ServiceReference1.LoginInfo>;
string comboname;
List<string> items = new List<string>();
for (int i = 0; i < list.Count(); i++)
{
comboname = list.ElementAt(i).UserName;
items.Add(comboname);
items.Sort();
}
//This is where i need something to convert the list<string> items to the IEnumerable<ServiceReference1.LoginInfo> list
//set the itemsource
RegisterPanel_CarrierComboBox.ItemsSource = list;
我再次尝试将此字符串列表转换为可枚举的主要原因是因为我需要能够将其设置为我的项目源,以使我的组合框正常工作。一旦这一切都设置好了,我就可以解决下一个问题,即为什么当我切换到另一个堆栈面板时我的组合框不会清除。
任何和所有答案都会有所帮助。谢谢
根据我从您的代码中了解到的情况,您只想按用户名对 LoginInfo 列表进行排序。 正确吗?
IEnumerable<LoginInfo> list = ...
list = list.OrderBy(t => t.username).ToList();