本文整理汇总了C#中System.Array.SetValue方法的典型用法代码示例。如果您正苦于以下问题:C# Array.SetValue方法的具体用法?C# Array.SetValue怎么用?C# Array.SetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Array
的用法示例。
在下文中一共展示了Array.SetValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Sort
/// <summary>
/// Sort elements in an Array object, using the Order
/// delegate to determine how items should be sorted.
/// </summary>
/// <param name="table">Array to be sorted</param>
/// <param name="sortHandler">Delegate to manage
/// sort order.</param>
public void Sort(Array table, Order sortHandler)
{
if(sortHandler == null)
throw new ArgumentNullException();
bool nothingSwapped = false;
int pass = 1;
while(nothingSwapped == false)
{
nothingSwapped = true;
for(int index = 0; index < table.Length - pass; ++index)
{
// Use an Order delegate to determine the sort order.
if(sortHandler(table.GetValue(index),
table.GetValue(index + 1)) == false)
{
nothingSwapped = false;
object temp = table.GetValue(index);
table.SetValue(table.GetValue(index + 1), index);
table.SetValue(temp, index + 1);
}
}
++pass;
}
}
示例2: swapTo
public static void swapTo(float input, Array dest, int pos)
{
byte[] tmpIn = BitConverter.GetBytes(input);
dest.SetValue(tmpIn[3], pos);
dest.SetValue(tmpIn[2], pos + 1);
dest.SetValue(tmpIn[1], pos + 2);
dest.SetValue(tmpIn[0], pos + 3);
}
示例3: Shuffle
public static void Shuffle(this Random rng, Array array)
{
int n = array.Length;
while (n > 1) {
int k = rng.Next (n--);
object temp = array.GetValue (n);
array.SetValue (array.GetValue (k), n);
array.SetValue (temp, k);
}
}
示例4: SortGenericArray
protected override void SortGenericArray(Array items, int left, int right)
{
int lo = left;
int hi = right;
if (lo >= hi)
{
return;
}
int mid = (lo + hi) / 2;
// Partition the items into two lists and Sort them recursively
SortGenericArray(items, lo, mid);
SortGenericArray(items, mid + 1, hi);
// Merge the two sorted lists
int end_lo = mid;
int start_hi = mid + 1;
while ((lo <= end_lo) && (start_hi <= hi))
{
if (this.comparer.Compare(items.GetValue(lo), items.GetValue(start_hi)) < 0)
{
lo++;
}
else
{
/*
* items[lo] >= items[start_hi]
* The next element comes from the second items,
* move the items[start_hi] element into the next
* position and shuffle all the other elements up.
*/
object T = items.GetValue(start_hi);
for (int k = start_hi - 1; k >= lo; k--)
{
items.SetValue(items.GetValue(k), k + 1);
}
items.SetValue(T, lo);
lo++;
end_lo++;
start_hi++;
}
}
}
示例5: Palette
public Palette(int randomSeed, int colorX, int colorY)
{
_random = new Random(randomSeed);
ColorList = new List<PaletteColor>();
Bitmap bmp;
try
{
bmp = Properties.Resources.ColourPalette;
_colorArr = Array.CreateInstance(typeof(Color), bmp.Height / colorX);
var y = colorY;
var ind = 0;
while (y < bmp.Height)
{
var clr = bmp.GetPixel(colorY, y);
y += colorX;
_colorArr.SetValue(clr, ind);
ind++;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
示例6: CopyTo
public void CopyTo(Array array, int index){
IEnumerator tablecell = this.GetEnumerator();
while(tablecell.MoveNext()){
index = index + 1;
array.SetValue(tablecell.Current, index);
}
}
示例7: CopyTo
public void CopyTo(Array array, int index)
{
foreach (object item in this)
{
array.SetValue(item, index++);
}
}
示例8: foreach
void ICollection.CopyTo(Array array, int index)
{
foreach (DesignSurface surface in this)
{
array.SetValue(surface, index++);
}
}
示例9: CopyTo
public void CopyTo(Array array, int index)
{
foreach (MethodData data in this)
{
array.SetValue(data, index++);
}
}
示例10: fillHeftArray
private void fillHeftArray(int spaceDimension, int histogramResolution, Array array, Array heftArray)
{
int cellNO = (int)Math.Pow(histogramResolution, spaceDimension);
int[] outerIndicesArray = new int[spaceDimension];
int[] innerIndicesArray = new int[spaceDimension];
int[] windowIndicesArray = new int[spaceDimension];
for (int outerCellIdx = 0; outerCellIdx < cellNO; outerCellIdx++)
{
transformator.transformCellIdxToIndicesArray(histogramResolution, outerIndicesArray, outerCellIdx);
for (int innerCellIdx = outerCellIdx; innerCellIdx < cellNO; innerCellIdx++)
{
transformator.transformCellIdxToIndicesArray(histogramResolution, innerIndicesArray, innerCellIdx);
int[] heftArrayIndeces;
int cellPoints;
bool validHeftArrayIndeces = transformator.mergeIndicesArrays(spaceDimension, outerIndicesArray,
innerIndicesArray, out heftArrayIndeces, out cellPoints);
if (validHeftArrayIndeces)
{
int cellValue = 0;
for (int windowIdx = outerCellIdx; windowIdx <= innerCellIdx; windowIdx++)
{
transformator.transformCellIdxToIndicesArray(histogramResolution, windowIndicesArray, windowIdx);
bool validSummableArrayIndeces = transformator.validateIndicesArrays(spaceDimension,
outerIndicesArray, innerIndicesArray, windowIndicesArray);
if (validSummableArrayIndeces)
{
cellValue += (int)array.GetValue(windowIndicesArray);
}
}
heftArray.SetValue(cellValue, heftArrayIndeces);
}
}
}
}
示例11: CopyTo
public virtual void CopyTo(Array array, int index)
{
foreach (object k in keys)
{
array.SetValue(hash[k], index++);
}
}
示例12: 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;
}
示例13:
void ICollection.CopyTo(Array dest, int index)
{
int count = this.Count;
for (int i = 0; i < count; i++)
{
dest.SetValue(this[i], index++);
}
}
示例14: foreach
void ICollection.CopyTo(Array myArr, int index)
{
foreach (BlockHistoryObject bho in _collectionArray)
{
myArr.SetValue(bho, index);
index++;
}
}
示例15: SortGenericArray
protected override void SortGenericArray(Array items, int left, int right)
{
int j;
int limit = items.Length;
int st = -1;
while (st < limit)
{
bool flipped = false;
st++;
limit--;
for (j = st; j < limit; j++)
{
if (this.comparer.Compare(items.GetValue(j), items.GetValue(j + 1)) > 0)
{
object T = items.GetValue(j);
items.SetValue(items.GetValue(j + 1), j);
items.SetValue(T,j + 1);
flipped = true;
}
} // end for
if (!flipped)
{
return;
}
for (j = limit; --j >= st; )
{
if (this.comparer.Compare(items.GetValue(j), items.GetValue(j + 1)) > 0)
{
object T = items.GetValue(j);
items.SetValue(items.GetValue(j + 1), j);
items.SetValue(T, j + 1);
flipped = true;
}
}
if (!flipped)
{
return;
}
}
}