本文整理汇总了C#中System.Array.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# Array.GetEnumerator方法的具体用法?C# Array.GetEnumerator怎么用?C# Array.GetEnumerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Array
的用法示例。
在下文中一共展示了Array.GetEnumerator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMaxValueLength
/// <summary>
/// Iterates through all values in the matrix or jagged array and finds maximum length required
/// to show any of the values contained.
/// </summary>
/// <param name="array">Matrix or jagged array through which this method will iterate.</param>
/// <returns>Number of characters sufficient to receive any formatted value contained in <paramref name="array" />.</returns>
private int GetMaxValueLength(Array array)
{
var maxLength = 0;
if (IsMultiLinedFormat)
{
var sfi = new ScalarFormatInfo(this);
sfi.ShowDataType = false;
sfi.ShowInstanceName = false;
if (array.Rank == 2)
{
maxLength = sfi.GetMaxValueLength(array.GetEnumerator());
}
else
{
// In jagged array we have to iterate through rows manually
var rowsEnumerator = array.GetEnumerator();
while (rowsEnumerator.MoveNext())
{
var row = (Array) rowsEnumerator.Current;
var curMaxLength = sfi.GetMaxValueLength(row.GetEnumerator());
maxLength = Math.Max(maxLength, curMaxLength);
}
}
}
return maxLength;
}
示例2: Slice
/// <summary>
/// Slices arrays of 2 and more dimensions.
/// </summary>
/// <param name="arr">Array to slice</param>
/// <param name="sliceDimensionIndex">Dimension to slice</param>
/// <param name="indexToSet">Index to set for the sliced dimension</param>
/// <returns>Sliced array</returns>
public static Array Slice(Array arr, int sliceDimensionIndex, int indexToSet)
{
var enumerator = arr.GetEnumerator();
enumerator.MoveNext();
Type elementType = enumerator.Current.GetType();
int[] lengthsSliced =
Enumerable.Range(0, arr.Rank)
.Where(i => i != sliceDimensionIndex)
.Select(arr.GetLength)
.ToArray();
int[] lowerBoundsSliced =
Enumerable.Range(0, arr.Rank)
.Where(i => i != sliceDimensionIndex)
.Select(arr.GetLowerBound)
.ToArray();
var arraySliced = Array.CreateInstance(elementType, lengthsSliced, lowerBoundsSliced);
var multiIndex1 = _firstIndex(arraySliced);
var multiIndex2 = _firstIndexBounded(arr, sliceDimensionIndex, indexToSet);
for (; multiIndex2 != null; multiIndex1 = _nextIndex(arraySliced, multiIndex1), multiIndex2 = _nextIndexBounded(arr, multiIndex2, sliceDimensionIndex))
{
arraySliced.SetValue(arr.GetValue(multiIndex2), multiIndex1);
}
return arraySliced;
}
示例3: Select_ListaWiadomosciOczekujacych_ExecuteCode
private void Select_ListaWiadomosciOczekujacych_ExecuteCode(object sender, EventArgs e)
{
results = BLL.tabWiadomosci.Select_Batch(workflowProperties.Web);
myEnum = results.GetEnumerator();
logSelected_HistoryOutcome = results.Length.ToString();
}
示例4: ForEachInArr
public static IEnumerator ForEachInArr(Array ary)
{
IEnumerator enumerator = ary.GetEnumerator();
if (enumerator == null)
{
throw ExceptionUtils.VbMakeException(0x5c);
}
return enumerator;
}
示例5: cmdGet_KartyKontrolne_ExecuteCode
private void cmdGet_KartyKontrolne_ExecuteCode(object sender, EventArgs e)
{
logSelected_HistoryDescription = "Karty kontrolne do obsługi";
results = BLL.tabKartyKontrolne.Get_ZwolnioneDoWysylki(workflowProperties.Web);
myEnum = results.GetEnumerator();
if (results != null) logSelected_HistoryOutcome = results.Length.ToString();
else logSelected_HistoryOutcome = "0";
}
示例6: DeepEquals
/// <summary>
/// Compare the two arrays
/// </summary>
/// <param name="a">Array A</param>
/// <param name="b">Array B</param>
/// <returns>True if the two array are equals, otherwise False.</returns>
/// <example>
/// <code>
/// int[] a = new int[] { 1, 2, 3, 4 };
/// int[] b = new int[] { 1, 2, 3, 4 };
/// Assert.IsTrue(Arrays.DeepEquals(a, b));
/// </code>
/// </example>
public static bool DeepEquals(Array a, Array b)
{
if (a == null && b == null)
{
return true;
}
if (ReferenceEquals(a, b))
{
return true;
}
if (a.Length != b.Length)
{
return false;
}
bool result = true;
IEnumerator enA = a.GetEnumerator();
IEnumerator enB = b.GetEnumerator();
while (enA.MoveNext() && enB.MoveNext())
{
if (enA.Current == null && enB.Current == null)
{
}
else if (enA.Current == null || enB.Current == null)
{
result = false;
break;
}
else if ((enA is Array) && (enB is Array))
{
result = DeepEquals((Array)enA, (Array)enB);
if (!result)
{
break;
}
}
else if (enA.Current == enB.Current)
{
}
else if (enA.Current.Equals(enB.Current))
{
}
else
{
result = false;
break;
}
}
return result;
}
示例7: ItemsEquals
private static bool ItemsEquals(Array x, Array y, Func<object, object, bool> compare)
{
var xe = x.GetEnumerator();
var ye = y.GetEnumerator();
while (xe.MoveNext() && ye.MoveNext())
{
if (!compare(xe.Current, ye.Current))
{
return false;
}
}
return true;
}
示例8: PrintAllValues
public static void PrintAllValues(Array myArr)
{
System.Collections.IEnumerator myEnumerator = myArr.GetEnumerator();
int i = 0;
int cols = myArr.GetLength(myArr.Rank - 1);
while (myEnumerator.MoveNext())
{
if (i < cols)
{
i++;
}
else
{
Console.WriteLine();
i = 1;
}
Console.Write("\t{0}", myEnumerator.Current);
}
Console.WriteLine();
}
示例9: PrintValues
private static void PrintValues(Array myArr, char mySeparator)
{
System.Collections.IEnumerator myEnumerator = myArr.GetEnumerator();
int i = 0;
int cols = myArr.GetLength(myArr.Rank - 1);
while (myEnumerator.MoveNext())
{
if (i < cols)
{
i++;
}
else
{
Console.WriteLine();
i = 1;
}
Console.Write("{0}{1}", mySeparator, myEnumerator.Current);
}
Console.WriteLine();
}
示例10: Equals
public static bool Equals(Array arr1, Array arr2)
{
if(object.ReferenceEquals(arr1, arr2))
{
return true;
}
if((arr1 == null && arr2 != null) || (arr1 != null && arr2 == null))
{
return false;
}
if(arr1.Length == arr2.Length)
{
IEnumerator e1 = arr1.GetEnumerator();
IEnumerator e2 = arr2.GetEnumerator();
while(e1.MoveNext())
{
e2.MoveNext();
if(e1.Current == null)
{
if(e2.Current != null)
{
return false;
}
}
else if(!e1.Current.Equals(e2.Current))
{
return false;
}
}
return true;
}
return false;
}
示例11: CompareArrays
static public void CompareArrays(Array a1, Array a2, string value)
{
if (a1 == null &&
a2 == null)
return;
Assert.IsFalse((a1 == null && a2 != null) || (a1 != null && a2 == null), value + " do not match - one array is null");
Assert.IsTrue(a1.Length == a2.Length, value + " do not match - array lengths do not match");
IEnumerator enum1 = a1.GetEnumerator();
IEnumerator enum2 = a2.GetEnumerator();
while (enum1.MoveNext() && enum2.MoveNext())
Assert.IsTrue(enum1.Current.Equals(enum2.Current), value + " do not match");
}
示例12: Curl
/// <summary>Curl an input array up into a multi-dimensional array.</summary>
/// <param name="input">The one dimensional array to be curled.</param>
/// <param name="dimens">The desired dimensions</param>
/// <returns>The curled array.</returns>
public static Array Curl(Array input, int[] dimens)
{
if (CountDimensions(input) != 1)
{
throw new SystemException("Attempt to curl non-1D array");
}
int test = 1;
for (int i = 0; i < dimens.Length; i += 1)
{
test *= dimens[i];
}
if (test != input.Length)
{
throw new SystemException("Curled array does not fit desired dimensions");
}
Array newArray = NewInstance(GetBaseClass(input), dimens);
int[] index = new int[dimens.Length];
index[index.Length - 1] = -1;
for (int i = 0; i < index.Length - 1; ++i)
{
index[i] = 0;
}
for (IEnumerator i = input.GetEnumerator(); i.MoveNext() && NextIndex(index, dimens); )
{
//NewInstance call creates a jagged array. So we cannot set the value using Array.SetValue
//as it works for multi-dimensional arrays and not for jagged
//newArray.SetValue(i.Current, index);
Array tarr = newArray;
for (int i2 = 0; i2 < index.Length - 1; i2++)
{
tarr = (Array)tarr.GetValue(index[i2]);
}
tarr.SetValue(i.Current, index[index.Length - 1]);
}
//int offset = 0;
//DoCurl(input, newArray, dimens, offset);
return newArray;
}
示例13: ForEachInArr
// Get the enumerator for an array.
public static IEnumerator ForEachInArr(Array ary)
{
return ary.GetEnumerator();
}
示例14: Select_ListaZadan_ExecuteCode
private void Select_ListaZadan_ExecuteCode(object sender, EventArgs e)
{
bool withAttachements = true;
zadania = BLL.tabZadania.Get_ZakonczoneDoArchiwizacji(workflowProperties.Web, withAttachements);
myEnum = zadania.GetEnumerator();
}
示例15: Select_ListaWiadomosci_ExecuteCode
private void Select_ListaWiadomosci_ExecuteCode(object sender, EventArgs e)
{
wiadomosci = BLL.tabWiadomosci.Get_GotoweDoArchiwizacji(workflowProperties.Web);
myEnum = wiadomosci.GetEnumerator();
}