ArraySegment<T> 생성자
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
구조체의 새 인스턴스를 초기화합니다 ArraySegment<T> .
오버로드
| Name | Description |
|---|---|
| ArraySegment<T>(T[]) |
지정된 배열의 ArraySegment<T> 모든 요소를 구분하는 구조체의 새 인스턴스를 초기화합니다. |
| ArraySegment<T>(T[], Int32, Int32) |
지정된 배열에 있는 요소의 ArraySegment<T> 지정된 범위를 구분하는 구조체의 새 인스턴스를 초기화합니다. |
예제
다음 코드 예제에서는 메서드에 ArraySegment<T> 구조를 전달합니다.
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();
}
}
/*
This code produces the following output.
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
*/
open System
// Print functions.
let printIndexAndValues (myArr: string []) =
for i = 0 to myArr.Length - 1 do
printfn $" [{i}] : {myArr[i]}"
printfn ""
let printIndexAndValuesSeg (arrSeg: ArraySegment<string>) =
for i = arrSeg.Offset to arrSeg.Offset + arrSeg.Count - 1 do
printfn $" [{i}] : {arrSeg.Array[i]}"
printfn ""
// Create and initialize a new string array.
let myArr = [| "The"; "quick"; "brown"; "fox"; "jumps"; "over"; "the"; "lazy"; "dog" |]
// Display the initial contents of the array.
printfn "The original array initially contains:"
printIndexAndValues myArr
// Define an array segment that contains the entire array.
let myArrSegAll = ArraySegment<string>(myArr)
// Display the contents of the ArraySegment.
printfn "The first array segment (with all the array's elements) contains:"
printIndexAndValuesSeg myArrSegAll
// Define an array segment that contains the middle five values of the array.
let myArrSegMid = ArraySegment<string>(myArr, 2, 5)
// Display the contents of the ArraySegment.
printfn "The second array segment (with the middle five elements) contains:"
printIndexAndValuesSeg 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.
printfn "After the first array segment is modified, the second array segment now contains:"
printIndexAndValuesSeg myArrSegMid
(*
This code produces the following output.
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
*)
Public Class SamplesArray
Public Shared Sub Main()
' Create and initialize a new string array.
Dim myArr As String() = {"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.
Dim myArrSegAll As New ArraySegment(Of 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.
Dim myArrSegMid As New ArraySegment(Of 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)
End Sub
Public Shared Sub PrintIndexAndValues(arrSeg As ArraySegment(Of String))
Dim i As Integer
For i = arrSeg.Offset To (arrSeg.Offset + arrSeg.Count - 1)
Console.WriteLine(" [{0}] : {1}", i, arrSeg.Array(i))
Next i
Console.WriteLine()
End Sub
Public Shared Sub PrintIndexAndValues(myArr as String())
Dim i As Integer
For i = 0 To (myArr.Length - 1)
Console.WriteLine(" [{0}] : {1}", i, myArr(i))
Next i
Console.WriteLine()
End Sub
End Class
'This code produces the following output.
'
'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
ArraySegment<T>(T[])
- Source:
- ArraySegment.cs
- Source:
- ArraySegment.cs
- Source:
- ArraySegment.cs
- Source:
- ArraySegment.cs
- Source:
- ArraySegment.cs
지정된 배열의 ArraySegment<T> 모든 요소를 구분하는 구조체의 새 인스턴스를 초기화합니다.
public:
ArraySegment(cli::array <T> ^ array);
public ArraySegment(T[] array);
new ArraySegment<'T> : 'T[] -> ArraySegment<'T>
Public Sub New (array As T())
매개 변수
- array
- T[]
래핑할 배열입니다.
예외
array은 null입니다.
설명
이 생성자는 의 ArraySegment<T> 모든 요소를 array구분하는 생성자를 만듭니다. 즉, Offset 속성은 ArraySegment<T> 0이고 해당 Count 속성의 길이 array는 0입니다. 배열의 ArraySegment<T> 일부만 구분하는 항목을 만들려면 생성자를 사용합니다 ArraySegment<T>(T[], Int32, Int32) .
원래 배열은 1차원이어야 하며 0부터 시작하는 인덱싱이 있어야 합니다.
여러 ArraySegment<T> 인스턴스는 동일한 원래 배열을 참조할 수 있으며 겹칠 수 있습니다.
추가 정보
적용 대상
ArraySegment<T>(T[], Int32, Int32)
- Source:
- ArraySegment.cs
- Source:
- ArraySegment.cs
- Source:
- ArraySegment.cs
- Source:
- ArraySegment.cs
- Source:
- ArraySegment.cs
지정된 배열에 있는 요소의 ArraySegment<T> 지정된 범위를 구분하는 구조체의 새 인스턴스를 초기화합니다.
public:
ArraySegment(cli::array <T> ^ array, int offset, int count);
public ArraySegment(T[] array, int offset, int count);
new ArraySegment<'T> : 'T[] * int * int -> ArraySegment<'T>
Public Sub New (array As T(), offset As Integer, count As Integer)
매개 변수
- array
- T[]
구분할 요소의 범위를 포함하는 배열입니다.
- offset
- Int32
범위 내 첫 번째 요소의 인덱스(0부터 시작)입니다.
- count
- Int32
범위의 요소 수입니다.
예외
array은 null입니다.
offset 또는 count 0보다 작습니다.
offset 에서 count 유효한 범위를 array지정하지 않습니다.
설명
원래 배열은 1차원이어야 하며 0부터 시작하는 인덱싱이 있어야 합니다.
여러 ArraySegment<T> 인스턴스는 동일한 원래 배열을 참조할 수 있으며 겹칠 수 있습니다.