当前位置: 首页>>代码示例>>C#>>正文


C# Array.SetValue方法代码示例

本文整理汇总了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;
     }
 }
开发者ID:ppatoria,项目名称:SoftwareDevelopment,代码行数:32,代码来源:BUBBLESORT.CS

示例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);
 }
开发者ID:dwickeroth,项目名称:covise,代码行数:8,代码来源:ByteSwap.cs

示例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);
     }
 }
开发者ID:dannisliang,项目名称:unity-tools-1,代码行数:10,代码来源:RandomExtensions.cs

示例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++;
                }
            }
        }
开发者ID:jihadbird,项目名称:firespider,代码行数:49,代码来源:MergeSorter.cs

示例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);
            }
        }
开发者ID:Exclr8,项目名称:CloudCore,代码行数:27,代码来源:Palette.cs

示例6: CopyTo

		public void CopyTo(Array array, int index){
			IEnumerator tablecell = this.GetEnumerator();
			while(tablecell.MoveNext()){
				index = index + 1;
				array.SetValue(tablecell.Current, index);
			}
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:7,代码来源:HtmlTableCellCollection.cs

示例7: CopyTo

 public void CopyTo(Array array, int index)
 {
     foreach (object item in this)
     {
         array.SetValue(item, index++);
     }
 }
开发者ID:dsmithson,项目名称:KnightwareCore,代码行数:7,代码来源:CompositeCollection.cs

示例8: foreach

 void ICollection.CopyTo(Array array, int index)
 {
     foreach (DesignSurface surface in this)
     {
         array.SetValue(surface, index++);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:7,代码来源:DesignSurfaceCollection.cs

示例9: CopyTo

 public void CopyTo(Array array, int index)
 {
     foreach (MethodData data in this)
     {
         array.SetValue(data, index++);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:7,代码来源:MethodDataCollection.cs

示例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);
                    }
                }
            }
        }
开发者ID:szalaigj,项目名称:TilingApplication,代码行数:35,代码来源:HeftArrayCreator.cs

示例11: CopyTo

		public virtual void CopyTo(Array array, int index)
		{
			foreach (object k in keys)
			{
				array.SetValue(hash[k], index++);
			}
		}
开发者ID:Xanagandr,项目名称:DisaOpenSource,代码行数:7,代码来源:LinkedDictionary.cs

示例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;
        }
开发者ID:pauldotknopf,项目名称:Noodle,代码行数:41,代码来源:PolygonMath.cs

示例13:

 void ICollection.CopyTo(Array dest, int index)
 {
     int count = this.Count;
     for (int i = 0; i < count; i++)
     {
         dest.SetValue(this[i], index++);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:8,代码来源:HtmlWindowCollection.cs

示例14: foreach

 void ICollection.CopyTo(Array myArr, int index)
 {
     foreach (BlockHistoryObject bho in _collectionArray)
     {
         myArr.SetValue(bho, index);
         index++;
     }
 }
开发者ID:ninedrafted,项目名称:MineFrog,代码行数:8,代码来源:BlockHistoryObject.cs

示例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;
                }
            }
        }
开发者ID:jihadbird,项目名称:firespider,代码行数:46,代码来源:BidirectionalBubbleSorter.cs


注:本文中的System.Array.SetValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。