ArraySegmentとは? わかりやすく解説

ArraySegment コンストラクタ


ArraySegment コンストラクタ (T[])

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

指定した配列内のすべての要素区切る ArraySegment クラス新しインスタンス初期化します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Dim array As T()

Dim instance As New ArraySegment(Of
 T)(array)
public ArraySegment (
    T[] array
)
public:
ArraySegment (
    array<T>^ array
)
public ArraySegment (
    T[] array
)
public function ArraySegment (
    array : T[]
)

パラメータ

array

ラップする配列

例外例外
例外種類条件

ArgumentNullException

arraynull 参照 (Visual Basic では Nothing) です。

解説解説

このコンストラクタによって、arrayすべての要素区切る ArraySegment作成されます。つまり、ArraySegmentOffset プロパティは 0 で、Count プロパティは、array長さなります配列一部だけを区切る ArraySegment作成するには、ArraySegment(T[],Int32,Int32) コンストラクタ使用します

元の配列は、0 から始まるインデックス番号を持つ 1 次元配列である必要があります

複数ArraySegment インスタンスは、同じ元の配列参照し重複して存在することが可能です。

使用例使用例

ArraySegment 構造体メソッドに渡すコード例次に示します

Imports System

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 'Main

    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 'PrintIndexAndValues
 

    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 'PrintIndexAndValues
 

End Class 'SamplesArray


'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

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

*/

using namespace System;


namespace Sample
{
    public ref class SampleArray  
    {
    public:
        static void Work()  
        {

            // Create and initialize a new string array.
            array <String^>^ words = {"The", "quick", "brown"
,
                "fox", "jumps", "over", "the",
 "lazy", "dog"};

            // Display the initial contents of the array.
            Console::WriteLine("The first array segment"
                " (with all the array's elements) contains:");
            PrintIndexAndValues(words);

            // Define an array segment that contains the entire array.
            ArraySegment<String^> segment(words);
            
            // Display the contents of the ArraySegment.
            Console::WriteLine("The first array segment"
                " (with all the array's elements) contains:");
            PrintIndexAndValues(segment);

            // Define an array segment that contains the middle five
 
            // values of the array.
            ArraySegment<String^> middle(words, 2, 5);
            
            // Display the contents of the ArraySegment.
            Console::WriteLine("The second array segment"
                " (with the middle five elements) contains:");
            PrintIndexAndValues(middle);

            // Modify the fourth element of the first array 
            // segment
            segment.Array[3] = "LION";

            // Display the contents of the second array segment 
            // middle. 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(middle);
            Console::ReadLine();
        }

        static void PrintIndexAndValues(ArraySegment<String^>^
 segment)  
        {
            for (int i = segment->Offset;
 
                i < (segment->Offset + segment->Count); i++)  
            {
                Console::WriteLine("   [{0}] : {1}", i,
                    segment->Array[i]);
            }
            Console::WriteLine();
        }

        static void PrintIndexAndValues(array<String^>^
 words) 
        {
            for (int i = 0; i < words->Length;
 i++)  
            {
                Console::WriteLine("   [{0}] : {1}", i,
                    words[i]);
            }
            Console::WriteLine();
        }
    };
}

int main()
{
    Sample::SampleArray::Work();
    return 0; 
}


    /* 
    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[], Int32, Int32)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

指定した配列内で指定した要素範囲区切る ArraySegment クラス新しインスタンス初期化します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

例外例外
例外種類条件

ArgumentNullException

arraynull 参照 (Visual Basic では Nothing) です。

ArgumentOutOfRangeException

offset または count が 0 未満です。

ArgumentException

offset および count で、array 内の有効な範囲指定されていません。

解説解説

元の配列は、0 から始まるインデックス番号を持つ 1 次元配列である必要があります

複数ArraySegment インスタンスは、同じ元の配列参照し重複して存在することが可能です。

使用例使用例

ArraySegment 構造体メソッドに渡すコード例次に示します

Imports System

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 'Main

    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 'PrintIndexAndValues
 

    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 'PrintIndexAndValues
 

End Class 'SamplesArray


'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

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

*/

using namespace System;


namespace Sample
{
    public ref class SampleArray  
    {
    public:
        static void Work()  
        {

            // Create and initialize a new string array.
            array <String^>^ words = {"The", "quick", "brown"
,
                "fox", "jumps", "over", "the",
 "lazy", "dog"};

            // Display the initial contents of the array.
            Console::WriteLine("The first array segment"
                " (with all the array's elements) contains:");
            PrintIndexAndValues(words);

            // Define an array segment that contains the entire array.
            ArraySegment<String^> segment(words);
            
            // Display the contents of the ArraySegment.
            Console::WriteLine("The first array segment"
                " (with all the array's elements) contains:");
            PrintIndexAndValues(segment);

            // Define an array segment that contains the middle five
 
            // values of the array.
            ArraySegment<String^> middle(words, 2, 5);
            
            // Display the contents of the ArraySegment.
            Console::WriteLine("The second array segment"
                " (with the middle five elements) contains:");
            PrintIndexAndValues(middle);

            // Modify the fourth element of the first array 
            // segment
            segment.Array[3] = "LION";

            // Display the contents of the second array segment 
            // middle. 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(middle);
            Console::ReadLine();
        }

        static void PrintIndexAndValues(ArraySegment<String^>^
 segment)  
        {
            for (int i = segment->Offset;
 
                i < (segment->Offset + segment->Count); i++)  
            {
                Console::WriteLine("   [{0}] : {1}", i,
                    segment->Array[i]);
            }
            Console::WriteLine();
        }

        static void PrintIndexAndValues(array<String^>^
 words) 
        {
            for (int i = 0; i < words->Length;
 i++)  
            {
                Console::WriteLine("   [{0}] : {1}", i,
                    words[i]);
            }
            Console::WriteLine();
        }
    };
}

int main()
{
    Sample::SampleArray::Work();
    return 0; 
}


    /* 
    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 ジェネリック構造体

メモ : この構造体は、.NET Framework version 2.0新しく追加されたものです。

1 次元配列セクション区切ります

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<SerializableAttribute> _
Public Structure ArraySegment(Of
 T)
Dim instance As ArraySegment(Of
 T)
[SerializableAttribute] 
public struct ArraySegment<T>
[SerializableAttribute] 
generic<typename T>
public value class ArraySegment
J# では、ジェネリックな型およびメソッド使用できますが、新規に宣言することはできません。
JScript では、ジェネリックな型およびメソッド使用できません。

型パラメータ

T

配列セグメント要素の型。

解説解説

ArraySegment は、配列内の要素範囲区切る配列ラッパーです。複数ArraySegment インスタンスは、同じ元の配列参照し重複して存在することが可能です。

Array プロパティからは、元の配列コピーではなく、元の配列全体返ります。そのため、Array プロパティから返され配列加えた変更は、元の配列適用されます。

元の配列は、0 から始まるインデックス番号を持つ 1 次元配列である必要があります

使用例使用例

ArraySegment 構造体メソッドに渡すコード例次に示します

Imports System

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 'Main

    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 'PrintIndexAndValues
 

    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 'PrintIndexAndValues
 

End Class 'SamplesArray


'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

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

*/

using namespace System;


namespace Sample
{
    public ref class SampleArray  
    {
    public:
        static void Work()  
        {

            // Create and initialize a new string array.
            array <String^>^ words = {"The", "quick", "brown"
,
                "fox", "jumps", "over", "the",
 "lazy", "dog"};

            // Display the initial contents of the array.
            Console::WriteLine("The first array segment"
                " (with all the array's elements) contains:");
            PrintIndexAndValues(words);

            // Define an array segment that contains the entire array.
            ArraySegment<String^> segment(words);
            
            // Display the contents of the ArraySegment.
            Console::WriteLine("The first array segment"
                " (with all the array's elements) contains:");
            PrintIndexAndValues(segment);

            // Define an array segment that contains the middle five
 
            // values of the array.
            ArraySegment<String^> middle(words, 2, 5);
            
            // Display the contents of the ArraySegment.
            Console::WriteLine("The second array segment"
                " (with the middle five elements) contains:");
            PrintIndexAndValues(middle);

            // Modify the fourth element of the first array 
            // segment
            segment.Array[3] = "LION";

            // Display the contents of the second array segment 
            // middle. 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(middle);
            Console::ReadLine();
        }

        static void PrintIndexAndValues(ArraySegment<String^>^
 segment)  
        {
            for (int i = segment->Offset;
 
                i < (segment->Offset + segment->Count); i++)  
            {
                Console::WriteLine("   [{0}] : {1}", i,
                    segment->Array[i]);
            }
            Console::WriteLine();
        }

        static void PrintIndexAndValues(array<String^>^
 words) 
        {
            for (int i = 0; i < words->Length;
 i++)  
            {
                Console::WriteLine("   [{0}] : {1}", i,
                    words[i]);
            }
            Console::WriteLine();
        }
    };
}

int main()
{
    Sample::SampleArray::Work();
    return 0; 
}


    /* 
    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 static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

ArraySegment プロパティ


ArraySegment メソッド


ArraySegment メンバ



このページでは「.NET Framework クラス ライブラリ リファレンス」からArraySegmentを検索した結果を表示しています。
Weblioに収録されているすべての辞書からArraySegmentを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からArraySegment を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ArraySegment」の関連用語

ArraySegmentのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ArraySegmentのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS