Tag: list

比较两个列表之间的差异

我试图检查c#两个List之间的区别。 例: List FirstList = new List(); List SecondList = new List(); FirstList填充以下值: FirstList.Add(“COM1”); FirstList.Add(“COM2”); SecondList填充以下值: SecondList.Add(“COM1”); SecondList.Add(“COM2”); SecondList.Add(“COM3”); 现在我想检查SecondList中的某些值是否等于FirstList值。 如果有相同的值,例如:COM1和COM2,它们在两个列表中,则从列表中过滤它们,并将其余值添加到另一个列表中。 因此,如果我要创建一个新的ThirdList ,它将只用“COM3”填充,因为其他值是重复的。 我怎样才能创建这样的支票?

将List <List >转换为C#中的List

我有一个List<List> 。 我想将它转换为List ,其中每个int都是唯一的。 我想知道是否有人使用LINQ有一个优雅的解决方案。 我希望能够使用Union方法,但每次都会创建一个新的List 。 所以我想避免做这样的事情: List allInts = new List(); foreach(List list in listOfLists) allInts = new List(allInts.Union(list)); 有什么建议? 谢谢!

用于自然分类的IComparer

我一直在寻找解决方案一段时间了。 当我使用字符串排序对下面排序时,我有一个列表: 10 10b 1111 1164 1174 23 23A 23B 23D 23E 我真的希望列表是: 10 10b 23 23A 23B 23D 23E 1111 1164 1174 数字排序也不能完成这项工作。

wpfcombobox结合

嗨,我正在尝试将List 绑定到组合框。 public OfferEditPage() { InitializeComponent(); cusmo = new CustomerViewModel(); DataContext = this; Cusco = cusmo.Customer.ToList(); customer.ItemsSource = Cusco; customer.DisplayMemberPath = “name”; customer.SelectedValuePath = “customerID”; customer.SelectedValue = “1”; } 我变得没有错误,但Combobox总是空的。 库斯科是我名单的财产。 我不知道这段代码有什么问题。 你能帮助我吗? 电贺 public class Customer { public int customerID { get; set; } public string name { get; set; } public string surname […]

List 的递归读取

我有List这种结构,具体来说它是一个“CategoryItem”对象。 这是我的“CategoryItem”对象的声明。 public class CategoryItem { public string Name { get; set; } public int CategoryID {get; set;} public int ParentID {get; set; } public List SubCategory {get; set;} } 这是我的示例数据结构: [0] CategoryID: 249 Name: “WelcomeNC” ParentID: 0 SubCategory: length=4 [0] CategoryID: 250 Name: “CNC” ParentID: 249 SubCategory: length=0 [1] CategoryID: 251 Name: “Production” ParentID: […]

将JSON对象反序列化为C#列表

我正在尝试使用Bill Reiss的教程在C#中反序列化给定的JSON文件。 对于非列表中的XML数据,此方法非常有效,但我希望使用以下结构反序列化JSON文件: public class Data { public string Att1 { get; set; } public string Att2 { get; set; } public string Att3 { get; set; } public string Att4 { get; set; } } public class RootObject { public List Listname { get; set; } } 我的问题是使用JSON.Net创建/将数据放入列表,然后在XAML页面上显示列表的能力。 到目前为止我的想法(这是行不通的): var resp = await client.DoRequestJsonAsync(“URL”); […]

在c#中设置/扩展List 长度

给定c#中的List是否有一种方法可以扩展它(在其容量内)并将新元素设置为null ? 我想要一些像memset一样的东西。 我不是在寻找糖,我想要快速的代码。 我知道在C中,操作可以在每个条目1-3个asm操作中完成。 我发现的最佳解决方案是: list.AddRange(Enumerable.Repeat(null, count-list.Count)); 然而,这是c#3.0(首选<3.0),可能正在生成和评估枚举器。 我目前的代码使用: while(list.Count < lim) list.Add(null); 所以这是时间成本的起点。 这样做的动机是我需要设置第n个元素,即使它是在旧的Count之后。

inheritanceList 来实现集合是个坏主意吗?

我曾经读过Imaar Spaanjars关于如何构建3层应用程序的文章。 ( http://imar.spaanjaars.com/416/building-layered-web-applications-with-microsoft-aspnet-20-part-1 )这已成为我编码的基础。 因此,我通过inheritanceList实现集合。 因此,如果我有一个名为Employee的类,要实现一个集合,我还将有一个Employees类,如下所示。 class Employee { int EmpID {get;set;} string EmpName {get;set;} } class Employees : List { public Employees(){} } 我从未真正质疑这一点,因为它为我做了工作。 但是现在我开始尝试一些事情,我不确定这是否是正确的方法。 例如,如果我想从Employees获得一个子集,例如 Employees newEmployees = (Employees) AllEmployees.FindAll(emp => emp.JoiningDate > DateTime.Now); 这会抛出System.InvalidCastException。 但是,如果我使用以下内容,则没有问题。 List newEmployees = AllEmployees.FindAll(emp => emp.JoiningDate > DateTime.Now); 那么如何实现Employees以便我不必在DAL或BLL中明确使用List ? 或者我怎样摆脱InvalidCastexception?

在CSV文件中写入C#对象列表

我有一个C#对象有8个大小为200的数组元素。我需要将这些数组打印到相应标签上的CSV文件中。 数据可能包含string,int和double。 例如: 时间1时间2日时间4时间4时间5时间6时间7 1 5 9 Mon 7.0 8 9 5 NA 2 3 3 。 。 200 200 200 Sun 200 200 200 200 200 哎呀,time1等是标签(Header)数据(8个列表有200个元素)应该在这些标签下写入。 感谢您的回复!

List AddToFront(T对象)的扩展方法如何?

我想为List类编写一个扩展方法,它接受一个对象并将其添加到前面而不是后面。 扩展方法真让我迷惑。 有人可以帮我解决这个问题吗? myList.AddToFront(T object);