在数组中查找第n个元素的逻辑 [英] logic to find nth element in an array
问题描述
在数组中找到第n个元素的逻辑
logic to find nth element in an array
推荐答案
下一次,请更具体地回答您的问题...
这是在c中使用数组的一些示例
Next time be more specific with your question...
here are some example to use array in c #
string[] mystringarray=new string[2];
mystring[0]=new string[2];
mystring[1]="2nd element of first diminution";
mystring[0][0]="first element of first dimension";
mystring[0][1]="2nd element of first dimension";
//finding nth element, eg nth= 0,0
Console.WriteLine(mystring[0][0]);
这是一个链接,它将为您提供教程
http://msdn.microsoft.com/en-us/library/aa288453 (v = vs.71).aspx [
here is a link, it will give you a tutorial
http://msdn.microsoft.com/en-us/library/aa288453(v=vs.71).aspx[^]
这个问题"几乎是胡言乱语:n-某些数组的元素是array[n]
.
但是,有一个陷阱:.NET允许创建不基于0的数组,即使此功能被称为不符合CLS.例如,对于多维数组,可以使用以下System.Array.CreateInstance
方法完成此操作:
This "problem" is nearly the poor gibberish: n-the element of some array isarray[n]
.
However, there is a catch: .NET allows to create arrays which are not 0-based, even though this feature is dubbed not CLS-compliant. For example, for a mutidimensional array, it can be done using thisSystem.Array.CreateInstance
method:
public static Array CreateInstance(
Type elementType,
int[] lengths,
int[] lowerBounds
)
请参阅:
http://msdn.microsoft.com/en-us/library/x836773a.aspx [ ^ ];
其他可能性,请参见:
http://msdn.microsoft.com/en-us/library/system.array.aspx [ ^ ].
那么如何索引这样的数组呢?自然地,在索引适当移动的情况下,根据每个维度的下限值,可以使用以下方法:
http://msdn.microsoft.com/en-us/library/system.array. getlowerbound.aspx [ ^ ].
我在上面引用的第一个MSDN帮助页面中显示的代码示例中对此进行了说明.
Please see:
http://msdn.microsoft.com/en-us/library/x836773a.aspx[^];
for other possibilities, please see:
http://msdn.microsoft.com/en-us/library/system.array.aspx[^].
How to index such arrays then? Naturally, with appropriate shift in the index, according to the value of lower bound in each dimension, using this method:
http://msdn.microsoft.com/en-us/library/system.array.getlowerbound.aspx[^].
This is illustrated in the code sample shown in the very first MSDN help page I referenced above.
这篇关于在数组中查找第n个元素的逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!