當前位置: 首頁>>代碼示例>>C#>>正文


C# Array.GetLength方法代碼示例

本文整理匯總了C#中System.Array.GetLength方法的典型用法代碼示例。如果您正苦於以下問題:C# Array.GetLength方法的具體用法?C# Array.GetLength怎麽用?C# Array.GetLength使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Array的用法示例。


在下文中一共展示了Array.GetLength方法的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();
 }
開發者ID:FabioNascimento,項目名稱:DICommander,代碼行數:32,代碼來源:ArrayOps.cs

示例2: LoadData

        // Load data
        public void LoadData( Array array )
        {
            //
            this.array = array;

            // set column and row headers
            FixedRows = 1;
            FixedColumns = 1;

            // Redim the grid
            Redim( array.GetLength( 0 ) + FixedRows, array.GetLength( 1 ) + FixedColumns );

            // Col Header Cell Template
            columnHeader = new CellColumnHeaderTemplate( );
            columnHeader.BindToGrid( this );

            // Row Header Cell Template
            rowHeader = new CellRowHeaderTemplate( );
            rowHeader.BindToGrid( this );

            // Header Cell Template (0,0 cell)
            cellHeader = new CellHeaderTemplate( );
            cellHeader.BindToGrid( this );

            // Data Cell Template
            dataCell = new CellArrayTemplate( array ); ;
            dataCell.BindToGrid( this );

            RefreshCellsStyle( );
        }
開發者ID:jdilt,項目名稱:iplab,代碼行數:31,代碼來源:GridArray.cs

示例3: ConvertArrayToShape

 public Shape ConvertArrayToShape(Array data)
 {
     width = data.GetLength(1);
     height = data.GetLength(0);
     shape = new Shape();
     double[] prevRow = ReadRow(data, 0);
     for (int y = 1; y < height; y++)
     {
         double[] nextRow = ReadRow(data, y);
         Vertex[] verts = GetRowOfVertices(nextRow, prevRow, y - 1);
         shape.Vertices.AddRange(verts);
         prevRow = nextRow;
     }
     return shape;
 }
開發者ID:adrianj,項目名稱:Direct3D-Testing,代碼行數:15,代碼來源:ShapeArrayFactory.cs

示例4: ArrayInfo

 static void ArrayInfo(String name, Array a)
 {
     Console.Write("{0} has length={1} rank={2} [", name, a.Length, a.Rank);
     for (int i = 0, stop=a.Rank; i<stop; i++)
         Console.Write(" {0}", a.GetLength(i));
     Console.WriteLine(" ]");
 }
開發者ID:walrus7521,項目名稱:code,代碼行數:7,代碼來源:Arrays.cs

示例5: CombinatorialBase

        // This is the GENERIC Type constructor.
        protected CombinatorialBase(Array arrayObjects, int nKlass)
        {
            // Check the validity of the arguments
            DoArgumentCheck(arrayObjects.Length, nKlass);

            m_nKlass = nKlass;

            // Always takes the ZERO (FIRST) dimension of the array. There is no
            // problem in manipulation multidimensional arrays.
            m_nMaxIndex = arrayObjects.GetLength(0) - 1;

            m_arrayIndeces = new int[m_nKlass];
            m_arrayIndecesDummy = new int[m_nKlass];

            m_arrayCurrentObj = new TouchPoint2[m_nKlass];
            //			m_arrayCurrentCombination = Array.CreateInstance(
            //				arrayObjects.GetValue(0).GetType(), m_nKlass);

            // Make a shallow copy of the source array.
            //			m_arrayObj = Array.CreateInstance( arrayObjects.GetValue(0).GetType(), arrayObjects.Length);

            //m_arrayObj = Array.CreateInstance(Type.GetType("System.Object"), arrayObjects.Length);
            //Array.Copy(arrayObjects, m_arrayObj, arrayObjects.Length);

            //TODO: review code
            m_arrayObj = new TouchPoint2[arrayObjects.Length];
            Array.Copy(arrayObjects, m_arrayObj, arrayObjects.Length);
        }
開發者ID:tuliosouza,項目名稱:ASG,代碼行數:29,代碼來源:CombinatorialBase.cs

示例6: BuildDigitsRepresentingAllIndices

 private static Digit BuildDigitsRepresentingAllIndices(Array subjectAsArray)
 {
     return Enumerable
         .Range(0, subjectAsArray.Rank)
         .Reverse()
         .Aggregate((Digit) null, (next, rank) => new Digit(subjectAsArray.GetLength(rank), next));
 }
開發者ID:leijiancd,項目名稱:fluentassertions,代碼行數:7,代碼來源:MultiDimensionalArrayEquivalencyStep.cs

示例7: 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;
        }
開發者ID:exxeleron,項目名稱:qXL,代碼行數:39,代碼來源:Utils.cs

示例8: ArrayLength

 static long ArrayLength(Array array, int i)
 {
     long n = 1;
     for ( ; i < array.Rank; i++ )
         n *= array.GetLength(i);
     return n;
 }
開發者ID:jlyonsmith,項目名稱:MonoYaml,代碼行數:7,代碼來源:YamlRepresenter.cs

示例9: AssertArray

 static void AssertArray(Array array, params object[] expectedValues)
 {
     Program.Assert(array.GetLength(0) == expectedValues.Length, "The arrays lengths are differents");
     for (int i = 0; i < expectedValues.Length; i++)
     {
         Program.Assert(array.GetValue(i).Equals(expectedValues[i]), "Unexpected values");
     }
 }
開發者ID:hesam,項目名稱:SketchSharp,代碼行數:8,代碼來源:GetRuntimeAttributeTest2.cs

示例10: LoadData

        // Load data
        public void LoadData( Array array )
        {
            //
            this.array = array;

            behavior = new CellBehavior( array );


            // set column and row headers
            FixedRows = 1;
            FixedColumns = 1;

            // Redim the grid
            Redim( array.GetLength( 0 ) + FixedRows, array.GetLength( 1 ) + FixedColumns );

            // Header
            this[0, 0] = new Header( );

            // Column headers
            for ( int i = 1; i < this.ColumnsCount; i++ )
            {
                ColumnHeader header = new ColumnHeader( i.ToString( ) );
                header.EnableSort = false;
                this[0, i] = header;
            }
            // Row headers
            for ( int i = 1; i < this.RowsCount; i++ )
            {
                this[i, 0] = new RowHeader( i.ToString( ) );
            }

            // Data cells
            Type type = array.GetValue( 0, 0 ).GetType( );
            for ( int i = 1, ia = 0; i < this.RowsCount; i++, ia++ )
            {
                for ( int j = 1, ja = 0; j < this.ColumnsCount; j++, ja++ )
                {
                    Cell cell = new Cell( array.GetValue( ia, ja ), type );
                    cell.Behaviors.Add( behavior );
                    this[i, j] = cell;
                }
            }

            Colorize( );
        }
開發者ID:jdilt,項目名稱:iplab,代碼行數:46,代碼來源:GridArrayInt.cs

示例11: ArrayTraverse

 public ArrayTraverse(Array array)
 {
     _maxLengths = new int[array.Rank];
     for (int i = 0; i < array.Rank; ++i)
     {
         _maxLengths[i] = array.GetLength(i) - 1;
     }
     Position = new int[array.Rank];
 }
開發者ID:Kostassoid,項目名稱:Liar,代碼行數:9,代碼來源:ArrayTraverse.cs

示例12: ArrayTraverse

 public ArrayTraverse(Array array)
 {
     this.Position = new int[array.Rank];
     this.maxLengths = new int[array.Rank];
     for (int i = 0; i < array.Rank; i++)
     {
         this.maxLengths[i] = array.GetLength(i) - 1;
     }
 }
開發者ID:MarinAtanasov,項目名稱:AppBrix.NetCore,代碼行數:9,代碼來源:ArrayTraverse.cs

示例13: ArrayToString

        /// <summary>
        /// The array to string.
        /// </summary>
        /// <param name="array">
        /// The array.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public static string ArrayToString(Array array)
        {
            StringBuilder text = new StringBuilder();

            for (int i = 0; i < array.GetLength(0); i++)
            {
                if (i != array.GetLength(0) - 1)
                {
                    text.Append(array.GetValue(i) + ", ");
                }
                else
                {
                    text.Append(array.GetValue(i));
                }
            }

            return text.ToString();
        }
開發者ID:Legoless,項目名稱:QRCode,代碼行數:27,代碼來源:BinaryExtensions.cs

示例14: serializeArray

             private void serializeArray(Array array)
             {
                m_ArrayData = new object[array.Length];
                m_ArrayDims = new int[array.Rank];
                for(var i=0; i<array.Rank; i++)
                    m_ArrayDims[i] = array.GetLength(i);

                var idx = 0;
                SerializationUtils.WalkArrayWrite(array, elm => m_ArrayData[idx++] =  elm );
             }
開發者ID:vlapchenko,項目名稱:nfx,代碼行數:10,代碼來源:CompositeArrayData.cs

示例15: WriteArray

 private void WriteArray(BinaryWriter bw, Array a, int dimension, params int[] indices)
 {
     if (a.Rank == dimension)
         WriteCore(bw, a.GetValue(indices));
     else
     {
         for (int i = 0; i < a.GetLength(dimension); i++)
             WriteArray(bw, a, dimension + 1, indices.Append(i));
     }
 }
開發者ID:CurlyBrackets,項目名稱:DynamicLibrary,代碼行數:10,代碼來源:ObjectSerializer.cs


注:本文中的System.Array.GetLength方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。