Tag: 列表

检查两个列表是否有碰撞元素?

有没有办法检查一个列表是否与另一个列表发生冲突? 例如: bool hit=false; foreach(var s in list2) { if (list1.Contains(s)) { hit = true; break; } } if (!hit) {

List .IndexOf()与List .FindIndex()的效率

其中一种方法 List.IndexOf()和 List.FindIndex() 在处理时间方面更有效? 此实例中的T类型为String 。

定义没有固定大小的双数组?

您好我的c#Arrays有问题。 我需要一个数组来存储一些数据…我的代码是那样的 double[] ATmittelMin; ATmittelMin[zaehlMittel] = Gradient(x, xATmax, y, yATmax); 但编译器说:未定义var如何定义没有固定大小的双数组? 非常感谢!

删除列表中除第一项以外的所有项目

让我们考虑如下列表 list包含的值为a,b,c,d …. 我需要一个查询来删除列表中除“a”以外的所有值。

.NET中的stack.ToList() – 元素的顺序?

在Stack上使用.ToList()扩展方法时,结果与弹出每个元素并添加到新列表(推送的内容相反)相同吗? 如果是这样,这是因为它实际上是迭代每个元素,还是内部反向存储元素并将数组滑入新的List ?

将多个用户输入添加到List c#

我试图从用户那里获得用户输入,直到用户没有输入任何内容(所以按下回车键),但它似乎没有正常工作。 用户应该能够添加任意数量的数字,并且一旦他们点击输入键而没有输入数字就应该显示它们。 码: using System; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Collections; using System.Collections.Generic; namespace Lab2 { class Program { static void Main(string[] args) { List numbersInput = new List(); Console.WriteLine(“Please enter an integer”); string input = Console.ReadLine(); numbersInput.Add(input); while (input != “”) { Console.WriteLine(“Please enter another integer: “); input = Console.ReadLine(); } if […]

C#Group由几个嵌套属性和列表值组成

我有这个对象结构: public class Root { public int Value1; public int Value2; public List NestedAList; } public class NestedA { public List NestedBList; public List NestedCList; } public class NestedB{ public int ValueB; public int ValueB2; } public class NestedC{ public int ValueC; public int ValueC2; } 我需要使用Root类中的所有值和它的嵌套列表对根对象进行分组。 我已经玩了一段时间,无法弄清楚如何/或者我是否可以在一个单独的组声明中做到这一点,或者最好的方法来实现这一点。 编辑:我需要按根属性,嵌套A属性,嵌套B属性和嵌套C属性分组的项目。 所以它是有道理的:我的真实对象有更多的属性,只显示我需要分组的属性,并可以用作起点。 提前致谢。 如果我们有这个元素 Root Value1 = […]

在跨平台xamarin项目(ios和android)中使用c#从查询列表中检索数据时面临参数exception错误

在跨平台xamarin项目(ios和android)中使用c#从查询列表中检索数据时遇到参数exception错误。 我试图从azure色(云)上的简单表中检索数据。 这是我的代码 try { var client = new MobileServiceClient(“https://eg.azurewebsites.net”); IMobileServiceTable regTable = client.GetTable(); Reg reg = new Reg(); string imail = uemail2.Text.ToString(); // This query to seach email var email1 = await regTable .Where(Reg => Reg.email.ToString() == imail) .Select(email => email.Text.ToString()) .ToListAsync(); notice3.Text = email1[0].ToString(); } catch (ArgumentException ex) { notice.Text = “Arguments Error” […]

ListView – 仅以编程方式选择索引

我正在尝试实现listbox(或listview): 我的问题是,我想在代码隐藏中将选定的索引绑定到属性。 它仅适用于表单启动,但我需要禁用用户更改选择。 Selectin将仅在programmaticaly上更改。 感谢所有的建议或解决方案:)

分组和选择整数列表的最快方法(最高出现次数)

我有一个包含100万到1亿整数的整数列表。 我想根据它们的出现次数对它们进行排名,并选择前K (此处为K=10 )的结果。 我已经尝试了4种不同的方法,我的方法1最快。 并行化没有超过我自己在Method1的分组代码,并且由于线程竞争条件导致排名不准确。 Method1和Method4结果准确无误,而Method3和Method3可能由于竞争条件而导致排名不准确。 现在,我正在寻找比Method1更快的任何代码,或者修复并行化方法,使它们准确然后比Method1更快。 class Benchmark { static List input = new List(); static void Main(string[] args) { int count = int.Parse(args[0]); Random rnd = new Random(); for (int i = 0; i < count; i++) input.Add(rnd.Next(1, count)); DoBench(); Console.ReadKey(); } private static void DoBench() { for (int i = 1; […]