本文整理汇总了C#中System.Array.GetLowerBound方法的典型用法代码示例。如果您正苦于以下问题:C# Array.GetLowerBound方法的具体用法?C# Array.GetLowerBound怎么用?C# Array.GetLowerBound使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Array
的用法示例。
在下文中一共展示了Array.GetLowerBound方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CodeRepresentation
public static string CodeRepresentation(Array a)
{
StringBuilder ret = new StringBuilder();
ret.Append(a.GetType().FullName);
ret.Append("(");
switch (a.Rank) {
case 1: {
for (int i = 0; i < a.Length; i++) {
if (i > 0) ret.Append(", ");
ret.Append(Ops.StringRepr(a.GetValue(i + a.GetLowerBound(0))));
}
}
break;
case 2: {
int imax = a.GetLength(0);
int jmax = a.GetLength(1);
for (int i = 0; i < imax; i++) {
ret.Append("\n");
for (int j = 0; j < jmax; j++) {
if (j > 0) ret.Append(", ");
ret.Append(Ops.StringRepr(a.GetValue(i + a.GetLowerBound(0), j + a.GetLowerBound(1))));
}
}
}
break;
default:
ret.Append(" Multi-dimensional array ");
break;
}
ret.Append(")");
return ret.ToString();
}
示例2: 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();
}
示例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: 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();
}
示例5: ForEach
/// <summary>
/// Modifies the specified array by applying the specified function to each element.
/// </summary>
/// <param name="a"></param>
/// <param name="func">object delegate(object o){}</param>
/// <returns></returns>
public static void ForEach(Array a, ForEachFunction func)
{
long[] ix = new long[a.Rank];
//Init index
for (int i = 0; i < ix.Length; i++) ix[i] = a.GetLowerBound(i);
//Loop through all items
for (long i = 0; i < a.LongLength; i++)
{
a.SetValue(func(a.GetValue(ix)), ix);
//Increment ix, the index
for (int j = 0; j < ix.Length; j++)
{
if (ix[j] < a.GetUpperBound(j))
{
ix[j]++;
break; //We're done incrementing.
}
else
{
//Ok, reset this one and increment the next.
ix[j] = a.GetLowerBound(j);
//If this is the last dimension, assert
//that we are at the last element
if (j == ix.Length - 1)
{
if (i < a.LongLength - 1) throw new Exception();
}
continue;
}
}
}
return;
}
示例6: 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
示例7: 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);
}
}
示例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: determineFirstIndicesArray
/// <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>
/// <returns></returns>
public int[] determineFirstIndicesArray(Array array)
{
int spaceDimension = array.Rank;
int[] firstIndicesArray = new int[spaceDimension];
for (int dimIdx = 0; dimIdx < spaceDimension; dimIdx++)
{
firstIndicesArray[dimIdx] = array.GetLowerBound(dimIdx);
}
return firstIndicesArray;
}
示例10: 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]--;
}
示例11: 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;
}
示例12: 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();
}
示例13: 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];
}
}
示例14: 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++);
}
}
示例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;
}