Tag: 数组

如何比较2个字符串数组并找到所有连续匹配并保存索引?

例如,如果我有以下2个数组: string[] userSelect = new string[] {“the”, “quick”, “brown”, “dog”, “jumps”, “over”}; string[] original = new string[] {“the”, “quick”, “brown”, “fox”, “jumps”, “over”, “the”, “lazy”, “dog”}; 我正在尝试将userSelect数组与原始数组进行比较,并根据索引获取所有连续匹配。 userSelect数组将始终由原始数组中的字符串组成。 所以输出如下: int[] match0 = new int[] {0, 1, 2}; // indices for “the quick brown” int[] match2 = new int[] {4, 5}; // indices for “jumps over” […]

序列化没有根元素的数组

我正在尝试在序列化XML时获得此结果 C:\test.txt 1 2 4 5 我已经尝试过不同的东西 [Serializable] [XmlRoot(“Test”)] public class Test { [XmlElement(“Category”)] public List Category= new List(); } [Serializable] [XmlRoot(“Category”)] public class Category { [XmlElement(“FileName”)] public string FileName { get; set; } [XmlElement(“Property”)] public List Properties = new List(); } [Serializable] public class Property { public string Prop1 { get; set; } public […]

当我们在C#和C ++中声明一个数组时有什么区别?

int[] arr = new int[3]; // C# int arr[3]; //C++ c ++中的数组声明将为三个整数分配一块内存。 我可以假设语言c#相同,但由于以下事实我不能。 c#中的每个变量都是struct或class或enum,As Array是一个类,arr应该是Array类的对象。 Intellisense还表明arr有许多与Array类函数相同的成员函数,但是Array是一个抽象类,因为我们无法实例化一个抽象类,arr可以是任何其他可能实现Array类的类的对象 如果我的演绎是正确的,我想知道 哪个类是arr的对象? 如果我的演绎错了 我想知道我哪里错了? 哪个Class数组是一个对象?

委托数组

我正在尝试从委托数组中调用委托函数。 我已经能够创建委托数组,但是如何调用委托? public delegate void pd(); public static class MyClass { static void p1() { //… } static void p2 () { //… } //… static pd[] delegates = new pd[] { new pd( MyClass.p1 ), new pd( MyClass.p2) /* … */ }; } public class MainClass { static void Main() { // Call pd[0] […]

在排序数组中找到小于x的最大值

假设我有一个整数的整数int[] ,我想搜索最接近的较小值到某个输入数。 例如,如果数组包含(1),(23),(57),(59),(120)并且输入为109,则输出应为59。 我只是想看看建议,并与我已有的方法进行比较。

在数组中查找重叠数据

我们正在编写一个C#应用程序,它将帮助删除不必要的数据中继器。 转发器只能在其接收的所有数据都被其他转发器接收的情况下被移除。 下面将解释我们作为第一步所需要的: 例如,我有int数组的集合 一个。 {1,2,3,4,5} 湾 {2,4,6,7} C。 {1,3,5,8,11,100} 它可能是数千个这样的arrays。 我需要找到可以删除的数组。 只有在其所有数字都包含在其他数组中的情况下,才能删除数组。 在上面的示例中,可以删除数组a,因为数字2和4在数组b中 ,数字1,3,5在数组c中 。 做这种手术的最佳方法是什么?

将Decimal数组转换为Double数组

什么是将decimal[]转换为double[]的有效且有希望优雅的咒语? 我正在使用一些相当大的数组。

数组的多少元素不为空?

数组是由假定的元素定义的,比如我有像String [] strArray = new String [50]这样的数组; 。 现在从50个元素中只分配了一些元素,剩下的都是null,然后我想要分配元素的数量。 就像这里只分配了30个元素然后我想要那个数字。

获取字符串数组的第一个和最后一个项目

如果我有以下字符串数组: string[] stringArray = {“one”, “two”, “three”, “four”}; 有没有办法从数组中获取C#中的第一个和最后一个项目(“one”,“4”),除了使用数组索引(stringArray [0],stringArray [3]),类似stringArray.First和stringArray。最后? 谢谢。

在’foreach’循环中获取数组键

如何在C#的foreach循环中获取当前元素的键? 例如: PHP foreach ($array as $key => $value) { echo(“$value is assigned to key: $key”); } 我想用C#做什么: int[] values = { 5, 14, 29, 49, 99, 150, 999 }; foreach (int val in values) { if(search <= val && !stop) { // Set key to a variable } }