本文整理汇总了C#中System.Array.GetUpperBound方法的典型用法代码示例。如果您正苦于以下问题:C# Array.GetUpperBound方法的具体用法?C# Array.GetUpperBound怎么用?C# Array.GetUpperBound使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Array
的用法示例。
在下文中一共展示了Array.GetUpperBound方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ArrayToDescriptor
public static string ArrayToDescriptor(Array array, Type type, VarIntStr typeHandle)
{
if (array.LongLength>MAX_ELM_COUNT)
throw new SlimSerializationException(StringConsts.SLIM_ARRAYS_OVER_MAX_ELM_ERROR.Args(array.LongLength, MAX_ELM_COUNT));
if (type==typeof(object[]))//special case for object[], because this type is very often used in Glue and other places
return "$2|"+array.Length.ToString();
var th = typeHandle.StringValue ??
( typeHandle.IntValue < TypeRegistry.STR_HNDL_POOL.Length ?
TypeRegistry.STR_HNDL_POOL[typeHandle.IntValue] :
'$'+typeHandle.IntValue.ToString()
);
var ar = array.Rank;
if (ar>MAX_DIM_COUNT)
throw new SlimSerializationException(StringConsts.SLIM_ARRAYS_OVER_MAX_DIMS_ERROR.Args(ar, MAX_DIM_COUNT));
var descr = new StringBuilder();
descr.Append( th );
descr.Append('|');//separator char
for(int i=0; i<ar; i++)
{
descr.Append(array.GetLowerBound(i));
descr.Append('~');
descr.Append(array.GetUpperBound(i));
if (i<ar-1)
descr.Append(',');
}
return descr.ToString();
}
示例2: CopyTo
public void CopyTo(Array array, int index)
{
if (this.isDisposed)
{
throw new ObjectDisposedException(name);
}
if (array == null)
{
throw new ArgumentNullException("array");
}
if ((index < array.GetLowerBound(0)) || (index > array.GetUpperBound(0)))
{
throw new ArgumentOutOfRangeException("index");
}
int num = array.Length - index;
int num2 = 0;
ArrayList list = new ArrayList();
ManagementObjectEnumerator enumerator = this.GetEnumerator();
while (enumerator.MoveNext())
{
ManagementBaseObject current = enumerator.Current;
list.Add(current);
num2++;
if (num2 > num)
{
throw new ArgumentException(null, "index");
}
}
list.CopyTo(array, index);
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:30,代码来源:ManagementObjectCollection.cs
示例3: Com2DArray2Array
//-------------------------------------------------------------------//
/// <summary>
/// Converts COM like 2dim array where one dimension is of length 1 to regular array.
/// </summary>
/// <param name="a">COM array</param>
/// <returns>regular array</returns>
public static object[] Com2DArray2Array(Array a)
{
if (a == null)
return null;
object[] converted = null;
switch (a.Rank)
{
case 1:
converted = new object[a.GetLength(0)];
for (var i = a.GetLowerBound(0); i <= a.GetUpperBound(0); i++)
{
converted[i] = a.GetValue(i);
}
break;
case 2:
{
var d1 = a.GetLength(0);
var d2 = a.GetLength(1);
var len = (d1 > d2) ? d1 : d2;
converted = new object[len];
var dim = (d1 > d2) ? 0 : 1;
for (var i = a.GetLowerBound(dim); i <= a.GetUpperBound(dim); i++)
{
converted[i - a.GetLowerBound(dim)] = a.GetValue((d1 == 1 ? a.GetLowerBound(0) : i),
(d2 == 1 ? a.GetLowerBound(1) : i));
}
}
break;
}
return converted;
}
示例4: CopyArray
// Copy the contents of an array.
public static Array CopyArray(Array arySrc, Array aryDest)
{
if(arySrc != null)
{
// Check that the arrays have the same rank and dimensions.
int rank = arySrc.Rank;
if(rank != aryDest.Rank)
{
ThrowExceptionInternal
(new InvalidCastException
(S._("VB_MismatchedRanks")));
}
for(int dim = 0; dim < rank; ++dim)
{
if(arySrc.GetUpperBound(dim) !=
aryDest.GetUpperBound(dim))
{
ThrowExceptionInternal
(new ArrayTypeMismatchException
(S._("VB_MismatchedDimensions")));
}
}
Array.Copy(arySrc, aryDest, arySrc.Length);
}
return aryDest;
}
示例5: ArrayToDescriptor
public static string ArrayToDescriptor(Array array,
TypeRegistry treg,
Type type = null,
string th = null)
{
if (type==null)
type = array.GetType();
if (array.LongLength>MAX_ELM_COUNT)
throw new SlimSerializationException(StringConsts.SLIM_ARRAYS_OVER_MAX_ELM_ERROR.Args(array.LongLength, MAX_ELM_COUNT));
if (type==typeof(object[]))//special case for object[], because this type is very often used in Glue and other places
return "$1|"+array.Length.ToString();
if (th==null)
th = treg.GetTypeHandle(type);
var ar = array.Rank;
if (ar>MAX_DIM_COUNT)
throw new SlimSerializationException(StringConsts.SLIM_ARRAYS_OVER_MAX_DIMS_ERROR.Args(ar, MAX_DIM_COUNT));
var descr = new StringBuilder(th);
descr.Append('|');//separator char
for(int i=0; i<ar; i++)
{
descr.Append(array.GetLowerBound(i));
descr.Append('~');
descr.Append(array.GetUpperBound(i));
if (i<ar-1)
descr.Append(',');
}
return descr.ToString();
}
示例6: AssertAllArrayElementsAreEqual
/// <summary>
/// Asserts that each element in the first array is equal to its corresponding element in the second array.
/// </summary>
public static void AssertAllArrayElementsAreEqual(Array first, Array second, IComparer comparer = null)
{
Assert.True(first.Length == second.Length, "The two arrays are not even the same size.");
for (int g = first.GetLowerBound(0); g < first.GetUpperBound(0); g++)
{
AssertArrayElementsAreEqual(first, second, g, comparer);
}
}
示例7: IsEnd
static bool IsEnd(Array array, Int32[] indexer)
{
for (var i = 0; i < array.Rank; ++i)
{
if (indexer[i] > array.GetUpperBound(i))
return true;
}
return false;
}
示例8: ArrayRankInfo
private static void ArrayRankInfo(String name, Array a) {
Console.WriteLine("Number of dimensions in \"{0}\" array (of type {1}): ",
name, a.GetType().ToString(), a.Rank);
for (int r = 0; r < a.Rank; r++) {
Console.WriteLine("Rank: {0}, LowerBound = {1}, UpperBound = {2}",
r, a.GetLowerBound(r), a.GetUpperBound(r));
}
Console.WriteLine();
}
示例9: ArrayIndexEnumerator
/// <summary>
/// Инициализирующий конструктор.
/// </summary>
/// <param name="arr">Массив, индексы которого перебираются.</param>
public ArrayIndexEnumerator(Array arr)
{
rank = arr.Rank;
az = new int[rank, 2];
index = new int[rank];
for(int a = 0; a < rank; a++)
{
az[a, 0] = arr.GetLowerBound(a);
index[a] = az[a, 0];
az[a, 1] = arr.GetUpperBound(a);
}
index[rank-1]--;
}
示例10: determineNextIndicesArray
/// <summary>
/// The following implementation is based on
/// stackoverflow.com/questions/9914230/iterate-through-an-array-of-arbitrary-dimension/9914326#9914326
/// </summary>
/// <param name="array"></param>
/// <param name="previousIndicesArray"></param>
/// <returns></returns>
public int[] determineNextIndicesArray(Array array, int[] previousIndicesArray)
{
int spaceDimension = array.Rank;
int[] nextIndicesArray = new int[spaceDimension];
previousIndicesArray.CopyTo(nextIndicesArray, 0);
for (int dimIdx = spaceDimension - 1; dimIdx >= 0; --dimIdx)
{
nextIndicesArray[dimIdx]++;
if (nextIndicesArray[dimIdx] <= array.GetUpperBound(dimIdx))
return nextIndicesArray;
nextIndicesArray[dimIdx] = array.GetLowerBound(dimIdx);
}
return null;
}
示例11: ASCIIfy
/// <summary>
/// Convert a list into a human-readable string representation. The
/// representation used is: (0 to 2) {1, 2, 3}
/// </summary>
/// <param name="data">The array to process</param>
/// <returns>A string containing the array data.</returns>
public static string ASCIIfy(Array data)
{
if ( data == null )
return "()";
StringBuilder sb = new StringBuilder("(");
sb.Append( String.Format( ResStrings.GetString( "ArrayLimits" ),
data.GetLowerBound( 0 ),
data.GetUpperBound( 0 ) ) );
sb.Append( ASCIIfy((IList)data) );
sb.Append( ")" );
return sb.ToString();
}
示例12: SetupLoopData
private static void SetupLoopData(Array arr, out int rank, out int[] dimensions, out int[] lowerBounds,
out int[] upperBounds)
{
rank = arr.Rank;
dimensions = new int[rank];
lowerBounds = new int[rank];
upperBounds = new int[rank];
for (int dimension = 0; dimension < rank; dimension++)
{
lowerBounds[dimension] = arr.GetLowerBound(dimension);
upperBounds[dimension] = arr.GetUpperBound(dimension);
//setup start values
dimensions[dimension] = lowerBounds[dimension];
}
}
示例13: CopyTo
public void CopyTo(Array array, int index)
{
IWbemQualifierSetFreeThreaded typeQualifierSet;
if (array == null)
{
throw new ArgumentNullException("array");
}
if ((index < array.GetLowerBound(0)) || (index > array.GetUpperBound(0)))
{
throw new ArgumentOutOfRangeException("index");
}
string[] pNames = null;
try
{
typeQualifierSet = this.GetTypeQualifierSet();
}
catch (ManagementException exception)
{
if ((this.qualifierSetType != QualifierType.PropertyQualifier) || (exception.ErrorCode != ManagementStatus.SystemProperty))
{
throw;
}
return;
}
int errorCode = typeQualifierSet.GetNames_(0, out pNames);
if (errorCode < 0)
{
if ((errorCode & 0xfffff000L) == 0x80041000L)
{
ManagementException.ThrowWithExtendedInfo((ManagementStatus) errorCode);
}
else
{
Marshal.ThrowExceptionForHR(errorCode);
}
}
if ((index + pNames.Length) > array.Length)
{
throw new ArgumentException(null, "index");
}
foreach (string str in pNames)
{
array.SetValue(new QualifierData(this.parent, this.propertyOrMethodName, str, this.qualifierSetType), index++);
}
}
示例14: GetArraySlice
public static object GetArraySlice( Array inputarray, int sliceindex )
{
int numoutputdimensions = inputarray.Rank - 1;
int[] newdimensions = new int[ numoutputdimensions ];
for( int i = 1; i < numoutputdimensions + 1; i++ )
{
newdimensions[ i - 1 ] = inputarray.GetUpperBound( i ) + 1;
}
Array newarray = Array.CreateInstance( inputarray.GetType().GetElementType(), newdimensions );
int[]traverseinputindex = new int[ numoutputdimensions + 1 ];
int[]traverseoutputindex = new int[ numoutputdimensions ];
traverseinputindex[0] = sliceindex;
bool bDone = false;
while( !bDone )
{
newarray.SetValue( inputarray.GetValue( traverseinputindex ), traverseoutputindex );
bool bUpdatedtraverseindex = false;
for( int i = numoutputdimensions - 1; i >= 0 && !bUpdatedtraverseindex; i-- )
{
traverseinputindex[i + 1]++;
traverseoutputindex[i]++;
if( traverseoutputindex[i] >= newdimensions[i] )
{
if( i == 0 )
{
bDone = true;
}
else
{
traverseinputindex[i + 1] = 0;
traverseoutputindex[i ] = 0;
}
}
else
{
bUpdatedtraverseindex = true;
}
}
}
return newarray;
}
示例15: TryGetRankDiff
private static bool TryGetRankDiff(Array x, Array y, out RankDiff rankDiff)
{
if (x.Length != y.Length || x.Rank != y.Rank)
{
rankDiff = new RankDiff(x, y);
return true;
}
for (var i = 0; i < x.Rank; i++)
{
if (x.GetLowerBound(i) != y.GetLowerBound(i) ||
x.GetUpperBound(i) != y.GetUpperBound(i))
{
rankDiff = new RankDiff(x, y);
return true;
}
}
rankDiff = null;
return false;
}