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


C# Array.GetLength方法代码示例

本文整理汇总了C#中Array.GetLength方法的典型用法代码示例。如果您正苦于以下问题:C# Array.GetLength方法的具体用法?C# Array.GetLength怎么用?C# Array.GetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Array的用法示例。


在下文中一共展示了Array.GetLength方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ArrayLength

 static long ArrayLength(Array array, int i)
 {
     long n = 1;
     for ( ; i < array.Rank; i++ )
         n *= array.GetLength(i);
     return n;
 }
开发者ID:jbruening,项目名称:YamlSerializer-Fork,代码行数:7,代码来源:YamlRepresenter.cs

示例2: PrintValues

 public static void PrintValues( 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();
 }
开发者ID:ppatoria,项目名称:SoftwareDevelopment,代码行数:15,代码来源:Array.cs

示例3: CreateBinaryArrayNode

 private YamlNode CreateBinaryArrayNode(Array array)
 {
     var type = array.GetType();
     var element = type.GetElementType();
     if ( !TypeUtils.IsPureValueType(element) )
         throw new InvalidOperationException(
             "Can not serialize {0} as binary because it contains non-value-type(s).".DoFormat(type.FullName));
     var elementSize = Marshal.SizeOf(element);
     var binary = new byte[array.LongLength * elementSize];
     int j = 0;
     for ( int i = 0; i < array.Length; i++ ) {
         IntPtr p = Marshal.UnsafeAddrOfPinnedArrayElement(array, i);
         Marshal.Copy(p, binary, j, elementSize);
         j += elementSize;
     }
     var dimension = "";
     if ( array.Rank > 1 ) {
         for ( int i = 0; i < array.Rank; i++ ) {
             if ( dimension != "" )
                 dimension += ", ";
             dimension += array.GetLength(i);
         }
         dimension = "[" + dimension + "]\r\n";
     }
     var result= str(TypeNameToYamlTag(type), dimension + Base64Encode(type, binary));
     result.Properties["Don'tCareLineBreaks"] = "true";
     return result;
 }
开发者ID:jbruening,项目名称:YamlSerializer-Fork,代码行数:28,代码来源:YamlRepresenter.cs

示例4: CreateArrayNodeSub

 private YamlNode CreateArrayNodeSub(Array array, int i, long[] indices)
 {
     var type= array.GetType();
     var element = type.GetElementType();
     var sequence = seq();
     if ( i == 0 ) {
         sequence.Tag = TypeNameToYamlTag(type);
         AppendToAppeared(array, sequence);
     }
     if ( element.IsPrimitive || element.IsEnum || element == typeof(decimal) )
         if ( array.Rank == 1 || ArrayLength(array, i+1) < 20 )
             sequence.Properties["Compact"] = "true";
     for ( indices[i] = 0; indices[i] < array.GetLength(i); indices[i]++ )
         if ( i == array.Rank - 1 ) {
             var n = ObjectToNode(array.GetValue(indices), type.GetElementType());
             sequence.Add(n);
         } else {
             var s = CreateArrayNodeSub(array, i + 1, indices);
             sequence.Add(s);
         }
     return sequence;
 }
开发者ID:jbruening,项目名称:YamlSerializer-Fork,代码行数:22,代码来源:YamlRepresenter.cs

示例5: GetCoercedArrayLiteral

 /// <summary>
 /// Gets the array literal in arrayValue coercing TypeNode[] and EnumNode[] as needed.
 /// </summary>
 /// <param name="arrayType">A TypeNode representing the array type</param>
 /// <param name="arrayValue">The value of the array literal to coerce</param>
 /// <returns>An Array object that has been coerced to the appropriate runtime type</returns>
 protected Array GetCoercedArrayLiteral(ArrayType arrayType, Array arrayValue)
 {
     if(arrayType == null)
         return null;
     if(arrayValue == null)
         return null;
     // Multi-dimensional arrays are not legal in attribute instances according section 17.1.3 of the C# 1.0 spec
     if(arrayValue.Rank != 1)
         return null;
     TypeNode elemType = arrayType.ElementType;
     if(elemType.typeCode != ElementType.ValueType && elemType.typeCode != ElementType.Class)
         return arrayValue;
     int arraySize = arrayValue.GetLength(0);
     Type et = elemType.GetRuntimeType();
     if(et == null)
         return null;
     Array val = Array.CreateInstance(et, arraySize);
     for(int i = 0; i < arraySize; i++)
         val.SetValue(this.GetCoercedLiteralValue(elemType, arrayValue.GetValue(i)), i);
     return val;
 }
开发者ID:modulexcite,项目名称:SHFB-1,代码行数:27,代码来源:Nodes.cs

示例6: CopyTo

		public virtual void CopyTo (Array array, int index)
		{
			if (controls == null)
				return;

			// can't use controls.CopyTo (array, index);
			// as we do not allocate it based on the true 
			// numbers of items we have in the collection
			// so we must re-implement Array.CopyTo :(

			if (array == null)
				throw new ArgumentNullException ("array");
			if (index + count > array.GetLowerBound (0) + array.GetLength (0))
				throw new ArgumentException ();
			if (array.Rank > 1)
				throw new RankException (Locale.GetText ("Only single dimension arrays are supported."));
			if (index < 0)
				throw new ArgumentOutOfRangeException ("index", Locale.GetText ("Value has to be >= 0."));

			for (int i=0; i < count; i++)
				array.SetValue (controls [i], i + index);
		}
开发者ID:nlhepler,项目名称:mono,代码行数:22,代码来源:ControlCollection.cs


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