本文整理汇总了C#中System.ArraySegment<T>.Count属性的典型用法代码示例。如果您正苦于以下问题:C# ArraySegment<T>.Count属性的具体用法?C# ArraySegment<T>.Count怎么用?C# ArraySegment<T>.Count使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.ArraySegment<T>
的用法示例。
在下文中一共展示了ArraySegment<T>.Count属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
public class SamplesArray {
public static void Main() {
// Create and initialize a new string array.
String[] myArr = { "The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog" };
// Display the initial contents of the array.
Console.WriteLine( "The original array initially contains:" );
PrintIndexAndValues( myArr );
// Define an array segment that contains the entire array.
ArraySegment<String> myArrSegAll = new ArraySegment<String>( myArr );
// Display the contents of the ArraySegment.
Console.WriteLine( "The first array segment (with all the array's elements) contains:" );
PrintIndexAndValues( myArrSegAll );
// Define an array segment that contains the middle five values of the array.
ArraySegment<String> myArrSegMid = new ArraySegment<String>( myArr, 2, 5 );
// Display the contents of the ArraySegment.
Console.WriteLine( "The second array segment (with the middle five elements) contains:" );
PrintIndexAndValues( myArrSegMid );
// Modify the fourth element of the first array segment myArrSegAll.
myArrSegAll.Array[3] = "LION";
// Display the contents of the second array segment myArrSegMid.
// Note that the value of its second element also changed.
Console.WriteLine( "After the first array segment is modified, the second array segment now contains:" );
PrintIndexAndValues( myArrSegMid );
}
public static void PrintIndexAndValues( ArraySegment<String> arrSeg ) {
for ( int i = arrSeg.Offset; i < (arrSeg.Offset + arrSeg.Count); i++ ) {
Console.WriteLine( " [{0}] : {1}", i, arrSeg.Array[i] );
}
Console.WriteLine();
}
public static void PrintIndexAndValues( String[] myArr ) {
for ( int i = 0; i < myArr.Length; i++ ) {
Console.WriteLine( " [{0}] : {1}", i, myArr[i] );
}
Console.WriteLine();
}
}
输出:
The original array initially contains: [0] : The [1] : quick [2] : brown [3] : fox [4] : jumps [5] : over [6] : the [7] : lazy [8] : dog The first array segment (with all the array's elements) contains: [0] : The [1] : quick [2] : brown [3] : fox [4] : jumps [5] : over [6] : the [7] : lazy [8] : dog The second array segment (with the middle five elements) contains: [2] : brown [3] : fox [4] : jumps [5] : over [6] : the After the first array segment is modified, the second array segment now contains: [2] : brown [3] : LION [4] : jumps [5] : over [6] : the