当前位置: 首页>>代码示例>>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;未经允许,请勿转载。