本文整理汇总了C#中System.Array.GetRank方法的典型用法代码示例。如果您正苦于以下问题:C# Array.GetRank方法的具体用法?C# Array.GetRank怎么用?C# Array.GetRank使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Array
的用法示例。
在下文中一共展示了Array.GetRank方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LastIndexOf
// Get the last index of a specific value within an array,
// starting at a particular index.
public static int LastIndexOf(Array array, Object value, int startIndex)
{
if(array == null)
{
throw new ArgumentNullException("array");
}
if(array.GetRank() != 1)
{
throw new RankException(_("Arg_RankMustBe1"));
}
if(startIndex < array.GetLowerBound(0) ||
startIndex > array.GetUpperBound(0) + 1)
{
throw new ArgumentOutOfRangeException
("startIndex", _("Arg_InvalidArrayIndex"));
}
return InnerLastIndexOf(array, value, array.GetLowerBound(0),
startIndex - array.GetLowerBound(0) + 1);
}
示例2: CopyTo
// Implement the ICollection interface.
public virtual void CopyTo(Array array, int index)
{
if(array == null)
{
throw new ArgumentNullException("array");
}
else if(GetRank() != 1)
{
throw new RankException(_("Arg_RankMustBe1"));
}
else if(array.GetRank() > 1)
{
throw new ArgumentException("array", _("Arg_RankMustBe1"));
}
else
{
Copy(this, GetLowerBound(0), array,
index + array.GetLowerBound(0), GetLength());
}
}
示例3: BinarySearch
// Perform a binary search within an array sub-range for a value,
// using a specific element comparer.
public static int BinarySearch(Array array, int index, int length,
Object value, IComparer comparer)
{
if(array == null)
{
throw new ArgumentNullException("array");
}
else if(array.GetRank() != 1)
{
throw new RankException(_("Arg_RankMustBe1"));
}
else if(index < array.GetLowerBound(0))
{
throw new ArgumentOutOfRangeException
("index", _("ArgRange_Array"));
}
else if(length < 0)
{
throw new ArgumentOutOfRangeException
("length", _("ArgRange_Array"));
}
else if((index - 1) > array.GetUpperBound(0) ||
length > (array.GetUpperBound(0) - index + 1))
{
throw new ArgumentException(_("Arg_InvalidArrayRange"));
}
return InnerBinarySearch(array, index, index + length - 1,
value, null);
}
示例4: Copy
// Copy the contents of one array into another (general-purpose version).
public static void Copy(Array sourceArray, int sourceIndex,
Array destinationArray,
int destinationIndex, int length)
{
// Validate the parameters.
if(sourceArray == null)
{
throw new ArgumentNullException("sourceArray");
}
if(destinationArray == null)
{
throw new ArgumentNullException("destinationArray");
}
if(sourceArray.GetRank() != destinationArray.GetRank())
{
throw new RankException(_("Arg_MustBeSameRank"));
}
int srcLower = sourceArray.GetLowerBound(0);
int srcLength = sourceArray.GetLength();
int dstLower = destinationArray.GetLowerBound(0);
int dstLength = destinationArray.GetLength();
if(sourceIndex < srcLower)
{
throw new ArgumentOutOfRangeException
("sourceIndex", _("ArgRange_Array"));
}
if(destinationIndex < dstLower)
{
throw new ArgumentOutOfRangeException
("destinationIndex", _("ArgRange_Array"));
}
if(length < 0)
{
throw new ArgumentOutOfRangeException
("length", _("ArgRange_NonNegative"));
}
int srcRelative = sourceIndex - srcLower;
int dstRelative = destinationIndex - dstLower;
if((srcLength - (srcRelative)) < length ||
(dstLength - (dstRelative)) < length)
{
throw new ArgumentException(_("Arg_InvalidArrayRange"));
}
// Get the array element types.
Type arrayType1 = sourceArray.GetType().GetElementType();
Type arrayType2 = destinationArray.GetType().GetElementType();
// Is this a simple array copy of the same element type?
if(arrayType1 == arrayType2)
{
InternalCopy
(sourceArray, srcRelative,
destinationArray, dstRelative,
length);
return;
}
// Check that casting between the types is possible,
// without using a narrowing conversion.
if(!ArrayTypeCompatible(arrayType1, arrayType2))
{
throw new ArrayTypeMismatchException
(_("Exception_ArrayTypeMismatch"));
}
// Copy the array contents the hard way. We don't have to
// worry about overlapping ranges because there is no way
// to get here if the source and destination are the same.
int index;
for(index = 0; index < length; ++index)
{
try
{
destinationArray.SetRelative(
Convert.ConvertObject(
sourceArray.GetRelative(srcRelative + index),
arrayType2), dstRelative + index);
}
catch(FormatException e)
{
throw new InvalidCastException(String.Format(_("InvalidCast_FromTo"),
arrayType1, arrayType2), e);
}
}
}
示例5: Sort
// Sort an array sub-range of keys using a comparer.
public static void Sort(Array array, int index, int length,
IComparer comparer)
{
if(array == null)
{
throw new ArgumentNullException("array");
}
if(array.GetRank() != 1)
{
throw new RankException(_("Arg_RankMustBe1"));
}
if(index < array.GetLowerBound(0))
{
throw new ArgumentOutOfRangeException
("index", _("ArgRange_Array"));
}
if(length < 0)
{
throw new ArgumentOutOfRangeException
("length", _("ArgRange_Array"));
}
if(index > array.GetUpperBound(0) + 1 ||
length > (array.GetUpperBound(0) - index + 1))
{
throw new ArgumentException(_("Arg_InvalidArrayRange"));
}
if(comparer == null)
{
comparer = Comparer.Default;
}
InnerSort(array, null, index, index + length - 1, comparer);
}
示例6: Reverse
// Reverse the order of elements in an array sub-range.
public static void Reverse(Array array, int index, int length)
{
if(array == null)
{
throw new ArgumentNullException("array");
}
if(array.GetRank() != 1)
{
throw new RankException(_("Arg_RankMustBe1"));
}
if(index < array.GetLowerBound(0))
{
throw new ArgumentOutOfRangeException
("index", _("ArgRange_Array"));
}
if(length < 0)
{
throw new ArgumentOutOfRangeException
("length", _("ArgRange_Array"));
}
if(index > array.GetUpperBound(0) ||
length > (array.GetUpperBound(0) - index + 1))
{
throw new ArgumentException(_("Arg_InvalidArrayRange"));
}
InnerReverse(array, index, index + length - 1);
}