Tag: arrays

List .Contains和T 。包含不同的行为

说我有这个class: public class Animal : IEquatable { public string Name { get; set; } public bool Equals(Animal other) { return Name.Equals(other.Name); } public override bool Equals(object obj) { return Equals((Animal)obj); } public override int GetHashCode() { return Name == null ? 0 : Name.GetHashCode(); } } 这是测试: var animals = new[] { new Animal { […]

将一维数组的索引转换为二维数组,即行和列

我有一个WinForms应用程序,我在插入名单和价格..名称和价格分别存储在二维数组。 现在,当我从listbox选择一条记录时,它只给我一个索引,我可以从中获取字符串名称和价格以更新该记录我必须更改该索引的名称和价格为此我要更新二维数组名称和价格。 但所选索引只是一维的。 我想将该索引转换为行和列。 怎么做? 但我正在这样的列表框中插入记录。 int row = 6, column = 10; for(int i=0;i<row;i++) { for(int j=0;j<column;j++) { value= row+" \t "+ column +" \t "+ name[i, j]+" \t " +price[i, j]; listbox.items.add(value); } }

C#中的struct marshal

我在C#中有以下结构 unsafe public struct control { public int bSetComPort; public int iComPortIndex; public int iBaudRate; public int iManufactoryID; public byte btAddressOfCamera; public int iCameraParam; public byte PresetNum; public byte PresetWaitTime; public byte Group; public byte AutoCruiseStatus; public byte Channel; public fixed byte Data[64]; } 我用来将它转换为字节数组[]的函数是 static byte[] structtobyte(object obj) { int len = Marshal.SizeOf(obj); byte[] […]

C#Arrays – string vs string

可能重复: C#中多维数组和数组数组之间的区别是什么? 谁能解释一下string[][]和string[,]之间的区别?

Array与Array List有显着差异?

可能重复: 何时在c#中使用ArrayList而不是array []? 从内存或处理器成本的角度来看,数组和arrayList对象之间是否存在显着差异?

array.GetLength(0)和array.GetUpperBound(0)之间的区别

这两种方法有什么区别,你何时使用一种而不是另一种? int[,] array = new int[4,3]; int length0 = array.GetLength(0); int upperbound0 = array.GetUpperBound(0); MSDN说GetLength返回GetUpperBound确定最大索引的元素数量,但是由于数组是用每个索引的元素初始化的,所以这有什么不同呢?

将数组添加到web.config中的键

我想知道是否有可能将一个数组作为一个值放在一个关键的例子中 这种语法有用吗?

Array,ArrayList和List之间有什么区别?

我想知道Array , ArrayList和List之间的确切区别是什么(因为它们都有类似的概念)以及在哪里使用一个而不是另一个。 例: 排列 对于Array,我们只能添加我们为此示例声明的类型int 。 int[] Array = new Int[5]; //Instansiation of an array for(int i = 0; i < Array.Length; i++) { Array[i] = i + 5; //Add values to each array index } 数组列表 我们可以像数组一样添加值 ArrayList arrayList = new ArrayList(); arrayList.Add(6); arrayList.Add(8); 名单 我们可以像在数组中一样添加值 List list = new List(); list.Add(6); List.Add(8); […]

在DataGridView中显示2d数组

我有一个2D数组。 我想在我的DataGridView打印数组,但它会抛出一个错误: [参数OutOfRangeException未处理] 这是我的代码 for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { dataGridView1[i, j].Value = state[i, j].h; //state[i, j].h this is my array dataGridView1[i, j].Style.BackColor pixelcolor[i,j]; dataGridView1[i, j].Style.ForeColor = Color.Gold; } }

删除Windows Phone C#app中的数组项,并且永远不会在下次应用启动时显示

我正在使用C#开发Windows Phone应用程序。 它在数组中有10000个元素。 我的程序sudo代码是这样的 Begin Get a random element from array Manipulate it Delete it End 应该从应用程序中透视删除该数组元素(即,我不应该在下一个应用程序启动时获取它) 如何轻松执行此任务。 请给我一些代码,以便我能够轻松理解。