Array.CreateInstance 메서드

정의

Array 클래스의 새 인스턴스를 초기화합니다.

오버로드

CreateInstance(Type, Int32)

지정한 Type 및 길이를 가진 인덱스가 0부터 시작하는 1차원 Array를 만듭니다.

CreateInstance(Type, Int32[])

지정한 Type 및 차원 길이를 가진 인덱스가 0부터 시작하는 다차원 Array를 만듭니다. 차원 길이가 32비트 정수 배열로 지정되어 있습니다.

CreateInstance(Type, Int64[])

지정한 Type 및 차원 길이를 가진 인덱스가 0부터 시작하는 다차원 Array를 만듭니다. 차원 길이가 64비트 정수 배열로 지정되어 있습니다.

CreateInstance(Type, Int32, Int32)

0부터 시작하는 인덱스를 사용하여 지정된 Type 및 차원 길이의 2차원 Array를 만듭니다.

CreateInstance(Type, Int32[], Int32[])

지정한 하한을 사용하여 지정한 Array 및 차원 길이의 다차원 Type 을 만듭니다.

CreateInstance(Type, Int32, Int32, Int32)

지정한 Type 및 차원 길이를 가진 인덱스가 0부터 시작하는 삼차원 Array를 만듭니다.

CreateInstance(Type, Int32)

Source:
Array.cs
Source:
Array.cs
Source:
Array.cs

지정한 Type 및 길이를 가진 인덱스가 0부터 시작하는 1차원 Array를 만듭니다.

public:
 static Array ^ CreateInstance(Type ^ elementType, int length);
public static Array CreateInstance (Type elementType, int length);
static member CreateInstance : Type * int -> Array
Public Shared Function CreateInstance (elementType As Type, length As Integer) As Array

매개 변수

elementType
Type

만들 ArrayType입니다.

length
Int32

만들 Array의 크기입니다.

반환

지정한 Type 및 지정한 길이를 가진 인덱스가 0부터 시작하는 새 1차원 Array입니다.

예외

elementType이(가) null인 경우

elementType은 유효한 Type이 아닙니다.

elementType은 지원되지 않습니다. 예를 들면 Void는 지원되지 않습니다.

또는

elementType이 개방형 제네릭 형식인 경우.

length가 0보다 작은 경우

예제

다음 코드 예제에서는 1차원 을 만들고 초기화하는 방법을 보여 있습니다 Array.

using namespace System;
void PrintValues( Array^ myArr );
void main()
{
   // Creates and initializes a one-dimensional Array instance of type Int32.
   Array^ my1DArray = Array::CreateInstance( Int32::typeid, 5 );
   for ( int i = my1DArray->GetLowerBound( 0 ); i <= my1DArray->GetUpperBound( 0 ); i++ )
      my1DArray->SetValue( i + 1, i );

   // Displays the values of the Array.
   Console::WriteLine(  "The one-dimensional Array instance contains the following values:" );
   PrintValues( my1DArray );
}

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();
}

/*
 This code produces the following output.
 
 The one-dimensional Array instance contains the following values:
     1    2    3    4    5
 */
open System

let printValues (myArr: Array) =
    let mutable i = 0
    let cols = myArr.GetLength(myArr.Rank - 1)
    for item in myArr do
        if i < cols then
            i <- i + 1
        else
            printfn ""
            i <- 1
        printf $"\t{item}"
    printfn ""

// Creates and initializes a one-dimensional Array of type int.
let my1DArray = Array.CreateInstance(typeof<int>, 5)
// let my1DArrayy = Array.zeroCreate<int> 5
for i = my1DArray.GetLowerBound 0 to my1DArray.GetUpperBound 0 do
    my1DArray.SetValue(i+1, i)

// Displays the values of the Array.
printfn "The one-dimensional Array contains the following values:"
printValues my1DArray


// This code produces the following output.
//     The one-dimensional Array contains the following values:
//         1    2    3    4    5
using System;
public class SamplesArray  {

   public static void Main()  {

      // Creates and initializes a one-dimensional Array of type int.
      Array my1DArray=Array.CreateInstance( typeof(int), 5 );
      for ( int i = my1DArray.GetLowerBound(0); i <= my1DArray.GetUpperBound(0); i++ )
         my1DArray.SetValue( i+1, i );

      // Displays the values of the Array.
      Console.WriteLine( "The one-dimensional Array contains the following values:" );
      PrintValues( my1DArray );
   }

   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();
   }
}
/*
This code produces the following output.

The one-dimensional Array contains the following values:
    1    2    3    4    5
*/
Public Class SamplesArray    
    
    Public Shared Sub Main()
        
        ' Creates and initializes a one-dimensional Array of type Int32.
        Dim my1DArray As Array = Array.CreateInstance(GetType(Int32), 5)
        Dim i As Integer
        For i = my1DArray.GetLowerBound(0) To my1DArray.GetUpperBound(0)
            my1DArray.SetValue(i + 1, i)
        Next i 
        ' Displays the values of the Array.
        Console.WriteLine("The one-dimensional Array contains the " _
           + "following values:")
        PrintValues(my1DArray)
        
    End Sub
    
    Public Shared Sub PrintValues(myArr As Array)
        Dim myEnumerator As System.Collections.IEnumerator = _
           myArr.GetEnumerator()
        Dim i As Integer = 0
        Dim cols As Integer = myArr.GetLength((myArr.Rank - 1))
        While myEnumerator.MoveNext()
            If i < cols Then
                i += 1
            Else
                Console.WriteLine()
                i = 1
            End If
            Console.Write(ControlChars.Tab + "{0}", myEnumerator.Current)
        End While
        Console.WriteLine()
    End Sub
End Class

' This code produces the following output.
' 
' The one-dimensional Array contains the following values:
'     1    2    3    4    5

설명

대부분의 클래스와 달리 는 Array 공용 생성자 대신 메서드를 제공하여 CreateInstance 런타임에 바인딩된 액세스를 허용합니다.

참조 형식 요소는 로 초기화 null됩니다. 값 형식 요소는 0으로 초기화됩니다.

이 메서드는 O (n) 작업, 여기서 nlength합니다.

F#에서 Array.zeroCreate 함수는 일반적으로 대신 사용됩니다.

적용 대상

CreateInstance(Type, Int32[])

Source:
Array.cs
Source:
Array.cs
Source:
Array.cs

지정한 Type 및 차원 길이를 가진 인덱스가 0부터 시작하는 다차원 Array를 만듭니다. 차원 길이가 32비트 정수 배열로 지정되어 있습니다.

public:
 static Array ^ CreateInstance(Type ^ elementType, ... cli::array <int> ^ lengths);
public static Array CreateInstance (Type elementType, params int[] lengths);
static member CreateInstance : Type * int[] -> Array
Public Shared Function CreateInstance (elementType As Type, ParamArray lengths As Integer()) As Array

매개 변수

elementType
Type

만들 ArrayType입니다.

lengths
Int32[]

만들 Array의 각 차원 크기를 나타내는 32비트 정수 배열입니다.

반환

지정한 Type 및 각 차원에 대해 지정한 길이를 가진 인덱스가 0부터 시작하는 새 다차원 Array입니다.

예외

elementType이(가) null인 경우

또는

lengths이(가) null인 경우

elementType은 유효한 Type이 아닙니다.

또는

lengths 배열에 1개 미만의 요소가 포함되어 있습니다.

elementType은 지원되지 않습니다. 예를 들면 Void는 지원되지 않습니다.

또는

elementType이 개방형 제네릭 형식인 경우.

lengths의 값이 0보다 작습니다.

예제

다음 코드 예제에서는 다차원 을 만들고 초기화하는 방법을 보여 줍니다 Array.

using namespace System;
void PrintValues( Array^ myArr );
void main()
{
   // Creates and initializes a multidimensional Array instance of type String.
   array<int>^myLengthsArray = {2,3,4,5};
   Array^ my4DArray = Array::CreateInstance( String::typeid, myLengthsArray );
   for ( int i = my4DArray->GetLowerBound( 0 ); i <= my4DArray->GetUpperBound( 0 ); i++ )
      for ( int j = my4DArray->GetLowerBound( 1 ); j <= my4DArray->GetUpperBound( 1 ); j++ )
         for ( int k = my4DArray->GetLowerBound( 2 ); k <= my4DArray->GetUpperBound( 2 ); k++ )
            for ( int l = my4DArray->GetLowerBound( 3 ); l <= my4DArray->GetUpperBound( 3 ); l++ )
            {
               array<int>^myIndicesArray = {i,j,k,l};
               my4DArray->SetValue( String::Concat( Convert::ToString( i ), j, k, l ), myIndicesArray );

            }

   // Displays the values of the Array.
   Console::WriteLine(  "The four-dimensional Array instance contains the following values:" );
   PrintValues( my4DArray );
}

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();
}

/*
 This code produces the following output.
 
 The four-dimensional Array instance contains the following values:
     0000    0001    0002    0003    0004
     0010    0011    0012    0013    0014
     0020    0021    0022    0023    0024
     0030    0031    0032    0033    0034
     0100    0101    0102    0103    0104
     0110    0111    0112    0113    0114
     0120    0121    0122    0123    0124
     0130    0131    0132    0133    0134
     0200    0201    0202    0203    0204
     0210    0211    0212    0213    0214
     0220    0221    0222    0223    0224
     0230    0231    0232    0233    0234
     1000    1001    1002    1003    1004
     1010    1011    1012    1013    1014
     1020    1021    1022    1023    1024
     1030    1031    1032    1033    1034
     1100    1101    1102    1103    1104
     1110    1111    1112    1113    1114
     1120    1121    1122    1123    1124
     1130    1131    1132    1133    1134
     1200    1201    1202    1203    1204
     1210    1211    1212    1213    1214
     1220    1221    1222    1223    1224
     1230    1231    1232    1233    1234
 */
open System

let printValues (myArray: Array) =
    let mutable i = 0
    let cols = myArray.GetLength(myArray.Rank - 1)
    for item in myArray do
        if i < cols then
            i <- i + 1
        else
            printfn ""
            i <- 1;
        printf $"\t{item}"
    printfn ""

// Creates and initializes a multidimensional Array of type string.
let my4DArray = Array.CreateInstance( typeof<string>, [| 2..5 |] )

for i = my4DArray.GetLowerBound 0 to my4DArray.GetUpperBound 0 do
    for j = my4DArray.GetLowerBound 1 to my4DArray.GetUpperBound 1 do
        for k = my4DArray.GetLowerBound 2 to my4DArray.GetUpperBound 2 do
            for l = my4DArray.GetLowerBound 3 to my4DArray.GetUpperBound 3 do
                let myIndicesArray = [| i; j; k; l |]
                my4DArray.SetValue($"{i}{j}{k}{l}", myIndicesArray)

// Displays the values of the Array.
printfn "The four-dimensional Array contains the following values:"
printValues my4DArray 


// This code produces the following output.
//     The four-dimensional Array contains the following values:
//         0000    0001    0002    0003    0004
//         0010    0011    0012    0013    0014
//         0020    0021    0022    0023    0024
//         0030    0031    0032    0033    0034
//         0100    0101    0102    0103    0104
//         0110    0111    0112    0113    0114
//         0120    0121    0122    0123    0124
//         0130    0131    0132    0133    0134
//         0200    0201    0202    0203    0204
//         0210    0211    0212    0213    0214
//         0220    0221    0222    0223    0224
//         0230    0231    0232    0233    0234
//         1000    1001    1002    1003    1004
//         1010    1011    1012    1013    1014
//         1020    1021    1022    1023    1024
//         1030    1031    1032    1033    1034
//         1100    1101    1102    1103    1104
//         1110    1111    1112    1113    1114
//         1120    1121    1122    1123    1124
//         1130    1131    1132    1133    1134
//         1200    1201    1202    1203    1204
//         1210    1211    1212    1213    1214
//         1220    1221    1222    1223    1224
//         1230    1231    1232    1233    1234
using System;
public class SamplesArray3  {

   public static void Main()  {

      // Creates and initializes a multidimensional Array of type string.
      int[] myLengthsArray = new int[4] { 2, 3, 4, 5 };
      Array my4DArray=Array.CreateInstance( typeof(string), myLengthsArray );
      for ( int i = my4DArray.GetLowerBound(0); i <= my4DArray.GetUpperBound(0); i++ )
         for ( int j = my4DArray.GetLowerBound(1); j <= my4DArray.GetUpperBound(1); j++ )
            for ( int k = my4DArray.GetLowerBound(2); k <= my4DArray.GetUpperBound(2); k++ )
               for ( int l = my4DArray.GetLowerBound(3); l <= my4DArray.GetUpperBound(3); l++ )  {
                  int[] myIndicesArray = new int[4] { i, j, k, l };
                  my4DArray.SetValue( Convert.ToString(i) + j + k + l, myIndicesArray );
               }

      // Displays the values of the Array.
      Console.WriteLine( "The four-dimensional Array contains the following values:" );
      PrintValues( my4DArray );
   }

   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();
   }
}
/*
This code produces the following output.

The four-dimensional Array contains the following values:
    0000    0001    0002    0003    0004
    0010    0011    0012    0013    0014
    0020    0021    0022    0023    0024
    0030    0031    0032    0033    0034
    0100    0101    0102    0103    0104
    0110    0111    0112    0113    0114
    0120    0121    0122    0123    0124
    0130    0131    0132    0133    0134
    0200    0201    0202    0203    0204
    0210    0211    0212    0213    0214
    0220    0221    0222    0223    0224
    0230    0231    0232    0233    0234
    1000    1001    1002    1003    1004
    1010    1011    1012    1013    1014
    1020    1021    1022    1023    1024
    1030    1031    1032    1033    1034
    1100    1101    1102    1103    1104
    1110    1111    1112    1113    1114
    1120    1121    1122    1123    1124
    1130    1131    1132    1133    1134
    1200    1201    1202    1203    1204
    1210    1211    1212    1213    1214
    1220    1221    1222    1223    1224
    1230    1231    1232    1233    1234
*/
Public Class SamplesArray    
    
    Public Shared Sub Main()
        
        ' Creates and initializes a multidimensional Array of type String.
        Dim myLengthsArray() As Integer = {2, 3, 4, 5}
        Dim my4DArray As Array = Array.CreateInstance(GetType(String), myLengthsArray)
        Dim i, j, k, l As Integer
        Dim myIndicesArray() As Integer
        For i = my4DArray.GetLowerBound(0) To my4DArray.GetUpperBound(0)
            For j = my4DArray.GetLowerBound(1) To my4DArray.GetUpperBound(1)
                For k = my4DArray.GetLowerBound(2) To my4DArray.GetUpperBound(2)
                    For l = my4DArray.GetLowerBound(3) To my4DArray.GetUpperBound(3)
                        myIndicesArray = New Integer() {i, j, k, l}
                        my4DArray.SetValue(Convert.ToString(i) + j.ToString() _
                           + k.ToString() + l.ToString(), myIndicesArray)
                    Next l
                Next k 
            Next j
        Next i

        ' Displays the values of the Array.
        Console.WriteLine("The four-dimensional Array contains the following values:")
        PrintValues(my4DArray)
    End Sub
    
    
    Public Shared Sub PrintValues(myArr As Array)
        Dim myEnumerator As System.Collections.IEnumerator = myArr.GetEnumerator()
        Dim i As Integer = 0
        Dim cols As Integer = myArr.GetLength(myArr.Rank - 1)
        While myEnumerator.MoveNext()
            If i < cols Then
                i += 1
            Else
                Console.WriteLine()
                i = 1
            End If
            Console.Write(ControlChars.Tab + "{0}", myEnumerator.Current)
        End While
        Console.WriteLine()
    End Sub
End Class

' This code produces the following output.
' 
' The four-dimensional Array contains the following values:
'     0000    0001    0002    0003    0004
'     0010    0011    0012    0013    0014
'     0020    0021    0022    0023    0024
'     0030    0031    0032    0033    0034
'     0100    0101    0102    0103    0104
'     0110    0111    0112    0113    0114
'     0120    0121    0122    0123    0124
'     0130    0131    0132    0133    0134
'     0200    0201    0202    0203    0204
'     0210    0211    0212    0213    0214
'     0220    0221    0222    0223    0224
'     0230    0231    0232    0233    0234
'     1000    1001    1002    1003    1004
'     1010    1011    1012    1013    1014
'     1020    1021    1022    1023    1024
'     1030    1031    1032    1033    1034
'     1100    1101    1102    1103    1104
 '    1110    1111    1112    1113    1114
'     1120    1121    1122    1123    1124
'     1130    1131    1132    1133    1134
'     1200    1201    1202    1203    1204
'     1210    1211    1212    1213    1214
'     1220    1221    1222    1223    1224
'     1230    1231    1232    1233    1234

설명

대부분의 클래스와 달리 는 Array 공용 생성자 대신 메서드를 제공하여 CreateInstance 런타임에 바인딩된 액세스를 허용합니다.

배열의 요소 lengths 수는 새 Array의 차원 수와 같아야 합니다. 배열의 lengths 각 요소는 새 Array에서 해당 차원의 길이를 지정해야 합니다.

참조 형식 요소는 로 초기화 null됩니다. 값 형식 요소는 0으로 초기화됩니다.

이 메서드는 O(n) 작업입니다. 여기서 n 는 의 lengths모든 값의 곱입니다.

적용 대상

CreateInstance(Type, Int64[])

Source:
Array.cs
Source:
Array.cs
Source:
Array.cs

지정한 Type 및 차원 길이를 가진 인덱스가 0부터 시작하는 다차원 Array를 만듭니다. 차원 길이가 64비트 정수 배열로 지정되어 있습니다.

public:
 static Array ^ CreateInstance(Type ^ elementType, ... cli::array <long> ^ lengths);
public static Array CreateInstance (Type elementType, params long[] lengths);
static member CreateInstance : Type * int64[] -> Array
Public Shared Function CreateInstance (elementType As Type, ParamArray lengths As Long()) As Array

매개 변수

elementType
Type

만들 ArrayType입니다.

lengths
Int64[]

만들 Array의 각 차원 크기를 나타내는 64비트 정수 배열입니다. 배열의 각 정수는 0과 Int32.MaxValue(포함) 사이여야 합니다.

반환

지정한 Type 및 각 차원에 대해 지정한 길이를 가진 인덱스가 0부터 시작하는 새 다차원 Array입니다.

예외

elementType이(가) null인 경우

또는

lengths이(가) null인 경우

elementType은 유효한 Type이 아닙니다.

또는

lengths 배열에 1개 미만의 요소가 포함되어 있습니다.

elementType은 지원되지 않습니다. 예를 들면 Void는 지원되지 않습니다.

또는

elementType이 개방형 제네릭 형식인 경우.

lengths 모든 값이 0보다 작거나 Int32.MaxValue보다 큽니다.

예제

다음 코드 예제에서는 다차원 을 만들고 초기화하는 방법을 보여 줍니다 Array.

using namespace System;
void PrintValues( Array^ myArr );
void main()
{
   // Creates and initializes a multidimensional Array instance of type String.
   array<int>^myLengthsArray = {2,3,4,5};
   Array^ my4DArray = Array::CreateInstance( String::typeid, myLengthsArray );
   for ( int i = my4DArray->GetLowerBound( 0 ); i <= my4DArray->GetUpperBound( 0 ); i++ )
      for ( int j = my4DArray->GetLowerBound( 1 ); j <= my4DArray->GetUpperBound( 1 ); j++ )
         for ( int k = my4DArray->GetLowerBound( 2 ); k <= my4DArray->GetUpperBound( 2 ); k++ )
            for ( int l = my4DArray->GetLowerBound( 3 ); l <= my4DArray->GetUpperBound( 3 ); l++ )
            {
               array<int>^myIndicesArray = {i,j,k,l};
               my4DArray->SetValue( String::Concat( Convert::ToString( i ), j, k, l ), myIndicesArray );

            }

   // Displays the values of the Array.
   Console::WriteLine(  "The four-dimensional Array instance contains the following values:" );
   PrintValues( my4DArray );
}

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();
}

/*
 This code produces the following output.
 
 The four-dimensional Array instance contains the following values:
     0000    0001    0002    0003    0004
     0010    0011    0012    0013    0014
     0020    0021    0022    0023    0024
     0030    0031    0032    0033    0034
     0100    0101    0102    0103    0104
     0110    0111    0112    0113    0114
     0120    0121    0122    0123    0124
     0130    0131    0132    0133    0134
     0200    0201    0202    0203    0204
     0210    0211    0212    0213    0214
     0220    0221    0222    0223    0224
     0230    0231    0232    0233    0234
     1000    1001    1002    1003    1004
     1010    1011    1012    1013    1014
     1020    1021    1022    1023    1024
     1030    1031    1032    1033    1034
     1100    1101    1102    1103    1104
     1110    1111    1112    1113    1114
     1120    1121    1122    1123    1124
     1130    1131    1132    1133    1134
     1200    1201    1202    1203    1204
     1210    1211    1212    1213    1214
     1220    1221    1222    1223    1224
     1230    1231    1232    1233    1234
 */
open System

let printValues (myArray: Array) =
    let mutable i = 0
    let cols = myArray.GetLength(myArray.Rank - 1)
    for item in myArray do
        if i < cols then
            i <- i + 1
        else
            printfn ""
            i <- 1;
        printf $"\t{item}"
    printfn ""

// Creates and initializes a multidimensional Array of type string.
let my4DArray = Array.CreateInstance( typeof<string>, [| 2..5 |] )

for i = my4DArray.GetLowerBound 0 to my4DArray.GetUpperBound 0 do
    for j = my4DArray.GetLowerBound 1 to my4DArray.GetUpperBound 1 do
        for k = my4DArray.GetLowerBound 2 to my4DArray.GetUpperBound 2 do
            for l = my4DArray.GetLowerBound 3 to my4DArray.GetUpperBound 3 do
                let myIndicesArray = [| i; j; k; l |]
                my4DArray.SetValue($"{i}{j}{k}{l}", myIndicesArray)

// Displays the values of the Array.
printfn "The four-dimensional Array contains the following values:"
printValues my4DArray 


// This code produces the following output.
//     The four-dimensional Array contains the following values:
//         0000    0001    0002    0003    0004
//         0010    0011    0012    0013    0014
//         0020    0021    0022    0023    0024
//         0030    0031    0032    0033    0034
//         0100    0101    0102    0103    0104
//         0110    0111    0112    0113    0114
//         0120    0121    0122    0123    0124
//         0130    0131    0132    0133    0134
//         0200    0201    0202    0203    0204
//         0210    0211    0212    0213    0214
//         0220    0221    0222    0223    0224
//         0230    0231    0232    0233    0234
//         1000    1001    1002    1003    1004
//         1010    1011    1012    1013    1014
//         1020    1021    1022    1023    1024
//         1030    1031    1032    1033    1034
//         1100    1101    1102    1103    1104
//         1110    1111    1112    1113    1114
//         1120    1121    1122    1123    1124
//         1130    1131    1132    1133    1134
//         1200    1201    1202    1203    1204
//         1210    1211    1212    1213    1214
//         1220    1221    1222    1223    1224
//         1230    1231    1232    1233    1234
using System;
public class SamplesArray3  {

   public static void Main()  {

      // Creates and initializes a multidimensional Array of type string.
      int[] myLengthsArray = new int[4] { 2, 3, 4, 5 };
      Array my4DArray=Array.CreateInstance( typeof(string), myLengthsArray );
      for ( int i = my4DArray.GetLowerBound(0); i <= my4DArray.GetUpperBound(0); i++ )
         for ( int j = my4DArray.GetLowerBound(1); j <= my4DArray.GetUpperBound(1); j++ )
            for ( int k = my4DArray.GetLowerBound(2); k <= my4DArray.GetUpperBound(2); k++ )
               for ( int l = my4DArray.GetLowerBound(3); l <= my4DArray.GetUpperBound(3); l++ )  {
                  int[] myIndicesArray = new int[4] { i, j, k, l };
                  my4DArray.SetValue( Convert.ToString(i) + j + k + l, myIndicesArray );
               }

      // Displays the values of the Array.
      Console.WriteLine( "The four-dimensional Array contains the following values:" );
      PrintValues( my4DArray );
   }

   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();
   }
}
/*
This code produces the following output.

The four-dimensional Array contains the following values:
    0000    0001    0002    0003    0004
    0010    0011    0012    0013    0014
    0020    0021    0022    0023    0024
    0030    0031    0032    0033    0034
    0100    0101    0102    0103    0104
    0110    0111    0112    0113    0114
    0120    0121    0122    0123    0124
    0130    0131    0132    0133    0134
    0200    0201    0202    0203    0204
    0210    0211    0212    0213    0214
    0220    0221    0222    0223    0224
    0230    0231    0232    0233    0234
    1000    1001    1002    1003    1004
    1010    1011    1012    1013    1014
    1020    1021    1022    1023    1024
    1030    1031    1032    1033    1034
    1100    1101    1102    1103    1104
    1110    1111    1112    1113    1114
    1120    1121    1122    1123    1124
    1130    1131    1132    1133    1134
    1200    1201    1202    1203    1204
    1210    1211    1212    1213    1214
    1220    1221    1222    1223    1224
    1230    1231    1232    1233    1234
*/
Public Class SamplesArray    
    
    Public Shared Sub Main()
        
        ' Creates and initializes a multidimensional Array of type String.
        Dim myLengthsArray() As Integer = {2, 3, 4, 5}
        Dim my4DArray As Array = Array.CreateInstance(GetType(String), myLengthsArray)
        Dim i, j, k, l As Integer
        Dim myIndicesArray() As Integer
        For i = my4DArray.GetLowerBound(0) To my4DArray.GetUpperBound(0)
            For j = my4DArray.GetLowerBound(1) To my4DArray.GetUpperBound(1)
                For k = my4DArray.GetLowerBound(2) To my4DArray.GetUpperBound(2)
                    For l = my4DArray.GetLowerBound(3) To my4DArray.GetUpperBound(3)
                        myIndicesArray = New Integer() {i, j, k, l}
                        my4DArray.SetValue(Convert.ToString(i) + j.ToString() _
                           + k.ToString() + l.ToString(), myIndicesArray)
                    Next l
                Next k 
            Next j
        Next i

        ' Displays the values of the Array.
        Console.WriteLine("The four-dimensional Array contains the following values:")
        PrintValues(my4DArray)
    End Sub
    
    
    Public Shared Sub PrintValues(myArr As Array)
        Dim myEnumerator As System.Collections.IEnumerator = myArr.GetEnumerator()
        Dim i As Integer = 0
        Dim cols As Integer = myArr.GetLength(myArr.Rank - 1)
        While myEnumerator.MoveNext()
            If i < cols Then
                i += 1
            Else
                Console.WriteLine()
                i = 1
            End If
            Console.Write(ControlChars.Tab + "{0}", myEnumerator.Current)
        End While
        Console.WriteLine()
    End Sub
End Class

' This code produces the following output.
' 
' The four-dimensional Array contains the following values:
'     0000    0001    0002    0003    0004
'     0010    0011    0012    0013    0014
'     0020    0021    0022    0023    0024
'     0030    0031    0032    0033    0034
'     0100    0101    0102    0103    0104
'     0110    0111    0112    0113    0114
'     0120    0121    0122    0123    0124
'     0130    0131    0132    0133    0134
'     0200    0201    0202    0203    0204
'     0210    0211    0212    0213    0214
'     0220    0221    0222    0223    0224
'     0230    0231    0232    0233    0234
'     1000    1001    1002    1003    1004
'     1010    1011    1012    1013    1014
'     1020    1021    1022    1023    1024
'     1030    1031    1032    1033    1034
'     1100    1101    1102    1103    1104
 '    1110    1111    1112    1113    1114
'     1120    1121    1122    1123    1124
'     1130    1131    1132    1133    1134
'     1200    1201    1202    1203    1204
'     1210    1211    1212    1213    1214
'     1220    1221    1222    1223    1224
'     1230    1231    1232    1233    1234

설명

대부분의 클래스와 달리 는 Array 공용 생성자 대신 메서드를 제공하여 CreateInstance 런타임에 바인딩된 액세스를 허용합니다.

배열의 요소 lengths 수는 새 Array의 차원 수와 같아야 합니다. 배열의 lengths 각 요소는 새 Array에서 해당 차원의 길이를 지정해야 합니다.

참조 형식 요소는 로 초기화 null됩니다. 값 형식 요소는 0으로 초기화됩니다.

이 메서드는 O(n) 작업입니다. 여기서 n 는 의 lengths모든 값의 곱입니다.

적용 대상

CreateInstance(Type, Int32, Int32)

Source:
Array.cs
Source:
Array.cs
Source:
Array.cs

0부터 시작하는 인덱스를 사용하여 지정된 Type 및 차원 길이의 2차원 Array를 만듭니다.

public:
 static Array ^ CreateInstance(Type ^ elementType, int length1, int length2);
public static Array CreateInstance (Type elementType, int length1, int length2);
static member CreateInstance : Type * int * int -> Array
Public Shared Function CreateInstance (elementType As Type, length1 As Integer, length2 As Integer) As Array

매개 변수

elementType
Type

만들 ArrayType입니다.

length1
Int32

만들 Array의 첫 번째 차원 크기입니다.

length2
Int32

만들 Array의 두 번째 차원 크기입니다.

반환

0부터 시작하는 인덱스를 사용하며 각 차원이 지정된 길이로 된 지정된 Type의 새로운 2차원 Array입니다.

예외

elementType이(가) null인 경우

elementType은 유효한 Type이 아닙니다.

elementType은 지원되지 않습니다. 예를 들면 Void는 지원되지 않습니다.

또는

elementType이 개방형 제네릭 형식인 경우.

length1가 0보다 작은 경우

또는

length2가 0보다 작은 경우

예제

다음 코드 예제에서는 2차원 을 만들고 초기화하는 방법을 보여 있습니다 Array.

using namespace System;
void PrintValues( Array^ myArr );
void main()
{
   // Creates and initializes a two-dimensional Array instance of type String.
   Array^ my2DArray = Array::CreateInstance( String::typeid, 2, 3 );
   for ( int i = my2DArray->GetLowerBound( 0 ); i <= my2DArray->GetUpperBound( 0 ); i++ )
      for ( int j = my2DArray->GetLowerBound( 1 ); j <= my2DArray->GetUpperBound( 1 ); j++ )
         my2DArray->SetValue( String::Concat( "abc", i, j ), i, j );
   
   // Displays the values of the Array.
   Console::WriteLine(  "The two-dimensional Array instance contains the following values:" );
   PrintValues( my2DArray );
}

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();
}

/* 
 This code produces the following output.
 
 The two-dimensional Array instance contains the following values:
     abc00    abc01    abc02
     abc10    abc11    abc12
 */
open System

let printValues (myArray: Array) =
    let mutable i = 0
    let cols = myArray.GetLength(myArray.Rank - 1)
    for item in myArray do
        if i < cols then
            i <- i + 1
        else
            printfn ""
            i <- 1;
        printf $"\t{item}"
    printfn ""

// Creates and initializes a two-dimensional Array of type string.
let my2DArray = Array.CreateInstance(typeof<string>, 2, 3)
// let my2DArray2 = Array2D.zeroCreate<string> 2 3

for i = my2DArray.GetLowerBound 0 to my2DArray.GetUpperBound 0 do
    for j = my2DArray.GetLowerBound 1 to my2DArray.GetUpperBound 1 do
        my2DArray.SetValue( $"abc{i}{j}", i, j )

// Displays the values of the Array.
printfn "The two-dimensional Array contains the following values:"
printValues my2DArray 


// This code produces the following output.
//     The two-dimensional Array contains the following values:
//         abc00    abc01    abc02
//         abc10    abc11    abc12
using System;
public class SamplesArray1  {

   public static void Main()  {

      // Creates and initializes a two-dimensional Array of type string.
      Array my2DArray=Array.CreateInstance( typeof(string), 2, 3 );
      for ( int i = my2DArray.GetLowerBound(0); i <= my2DArray.GetUpperBound(0); i++ )
         for ( int j = my2DArray.GetLowerBound(1); j <= my2DArray.GetUpperBound(1); j++ )
            my2DArray.SetValue( "abc" + i + j, i, j );

      // Displays the values of the Array.
      Console.WriteLine( "The two-dimensional Array contains the following values:" );
      PrintValues( my2DArray );
   }

   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();
   }
}
/*
This code produces the following output.

The two-dimensional Array contains the following values:
    abc00    abc01    abc02
    abc10    abc11    abc12
*/
Public Class SamplesArray    
    
    Public Shared Sub Main()
        
        ' Creates and initializes a two-dimensional Array of type String.
        Dim my2DArray As Array = Array.CreateInstance(GetType(String), 2, 3)
        Dim i, j As Integer        
        For i = my2DArray.GetLowerBound(0) To my2DArray.GetUpperBound(0)
            For j = my2DArray.GetLowerBound(1) To my2DArray.GetUpperBound(1)
                my2DArray.SetValue("abc" + i.ToString() + j.ToString(), i, j)
            Next j 
        Next i

        ' Displays the values of the Array.
        Console.WriteLine("The two-dimensional Array contains the " _
           + "following values:")
        PrintValues(my2DArray)
    End Sub   
    
    Public Shared Sub PrintValues(myArr As Array)
        Dim myEnumerator As System.Collections.IEnumerator = _
           myArr.GetEnumerator()
        Dim i As Integer = 0
        Dim cols As Integer = myArr.GetLength(myArr.Rank - 1)
        While myEnumerator.MoveNext()
            If i < cols Then
                i += 1
            Else
                Console.WriteLine()
                i = 1
            End If
            Console.Write(ControlChars.Tab + "{0}", myEnumerator.Current)
        End While
        Console.WriteLine()
    End Sub
End Class

' This code produces the following output.
' 
' The two-dimensional Array contains the following values:
'     abc00    abc01    abc02
'     abc10    abc11    abc12

설명

대부분의 클래스와 달리 는 Array 공용 생성자 대신 메서드를 제공하여 CreateInstance 런타임에 바인딩된 액세스를 허용합니다.

참조 형식 요소는 로 초기화 null됩니다. 값 형식 요소는 0으로 초기화됩니다.

이 메서드는 O(n) 작업이며 여기서 n 는 및 length2의 곱입니다length1.

F#에서는 Array2D.zeroCreate 함수를 대신 사용할 수 있습니다.

적용 대상

CreateInstance(Type, Int32[], Int32[])

Source:
Array.cs
Source:
Array.cs
Source:
Array.cs

지정한 하한을 사용하여 지정한 Array 및 차원 길이의 다차원 Type 을 만듭니다.

public:
 static Array ^ CreateInstance(Type ^ elementType, cli::array <int> ^ lengths, cli::array <int> ^ lowerBounds);
public static Array CreateInstance (Type elementType, int[] lengths, int[] lowerBounds);
static member CreateInstance : Type * int[] * int[] -> Array
Public Shared Function CreateInstance (elementType As Type, lengths As Integer(), lowerBounds As Integer()) As Array

매개 변수

elementType
Type

만들 ArrayType입니다.

lengths
Int32[]

만들 Array 의 각 차원 크기를 포함하는 1차원 배열입니다.

lowerBounds
Int32[]

만들 Array 의 각 차원 하한(시작 인덱스)을 포함하는 1차원 배열입니다.

반환

각 차원에 대해 지정한 길이 및 하한을 가진 지정한 Array 의 새 다차원 Type 입니다.

예외

elementType이(가) null인 경우

또는

lengthsnull입니다.

또는

lowerBounds이(가) null인 경우

elementType은 유효한 Type이 아닙니다.

또는

lengths 배열에 1개 미만의 요소가 포함되어 있습니다.

또는

lengthslowerBounds 배열에 들어 있는 요소 수가 다른 경우

elementType은 지원되지 않습니다. 예를 들면 Void는 지원되지 않습니다.

또는

elementType이 개방형 제네릭 형식인 경우.

lengths의 값이 0보다 작습니다.

또는

lowerBounds 모든 값이 매우 크면 차원의 하한 및 길이 합계가 Int32.MaxValue보다 큽니다.

예제

다음 코드 예제에서는 지정된 하한을 사용하여 다차원 Array 을 만들고 초기화하는 방법을 보여 줍니다.

using namespace System;
void PrintValues( Array^ myArr );
void main()
{
   // Creates and initializes a multidimensional Array instance of type String.
   array<int>^myLengthsArray = {3,5};
   array<int>^myBoundsArray = {2,3};
   Array^ myArray = Array::CreateInstance( String::typeid, myLengthsArray, myBoundsArray );
   for ( int i = myArray->GetLowerBound( 0 ); i <= myArray->GetUpperBound( 0 ); i++ )
      for ( int j = myArray->GetLowerBound( 1 ); j <= myArray->GetUpperBound( 1 ); j++ )
      {
         array<int>^myIndicesArray = {i,j};
         myArray->SetValue( String::Concat( Convert::ToString( i ), j ), myIndicesArray );

      }

   // Displays the lower bounds and the upper bounds of each dimension.
   Console::WriteLine(  "Bounds:\tLower\tUpper" );
   for ( int i = 0; i < myArray->Rank; i++ )
      Console::WriteLine(  "{0}:\t{1}\t{2}", i, myArray->GetLowerBound( i ), myArray->GetUpperBound( i ) );

   // Displays the values of the Array.
   Console::WriteLine(  "The Array instance contains the following values:" );
   PrintValues( myArray );
}

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();
}

/* 
 This code produces the following output.
 
 Bounds:    Lower    Upper
 0:    2    4
 1:    3    7
 The Array instance contains the following values:
     23    24    25    26    27
     33    34    35    36    37
     43    44    45    46    47
 */
open System

let printValues (myArray: Array) =
    let mutable i = 0
    let cols = myArray.GetLength(myArray.Rank - 1)
    for item in myArray do
        if i < cols then
            i <- i + 1
        else
            printfn ""
            i <- 1;
        printf $"\t{item}"
    printfn ""

// Creates and initializes a multidimensional Array of type string.
let myLengthsArray = [| 3; 5 |]
let myBoundsArray = [| 2; 3 |]
let myArray = Array.CreateInstance(typeof<string>, myLengthsArray, myBoundsArray)
for i = myArray.GetLowerBound 0 to myArray.GetUpperBound 0 do
    for j = myArray.GetLowerBound 1 to myArray.GetUpperBound 1 do
        let myIndicesArray = [| i; j |]
        myArray.SetValue($"{i}{j}", myIndicesArray)

// Displays the lower bounds and the upper bounds of each dimension.
printfn "Bounds:\tLower\tUpper"
for  i = 0 to myArray.Rank - 1 do
    printfn $"{i}:\t{myArray.GetLowerBound i}\t{myArray.GetUpperBound i}"

// Displays the values of the Array.
printfn "The Array contains the following values:"
printValues myArray 


// This code produces the following output.
//     Bounds:    Lower    Upper
//     0:         2        4
//     1:         3        7
//     The Array contains the following values:
//         23    24    25    26    27
//         33    34    35    36    37
//         43    44    45    46    47
using System;
public class SamplesArray4  {

   public static void Main()  {

      // Creates and initializes a multidimensional Array of type string.
      int[] myLengthsArray = new int[2] { 3, 5 };
      int[] myBoundsArray = new int[2] { 2, 3 };
      Array myArray=Array.CreateInstance( typeof(string), myLengthsArray, myBoundsArray );
      for ( int i = myArray.GetLowerBound(0); i <= myArray.GetUpperBound(0); i++ )
         for ( int j = myArray.GetLowerBound(1); j <= myArray.GetUpperBound(1); j++ )  {
            int[] myIndicesArray = new int[2] { i, j };
            myArray.SetValue( Convert.ToString(i) + j, myIndicesArray );
         }

      // Displays the lower bounds and the upper bounds of each dimension.
      Console.WriteLine( "Bounds:\tLower\tUpper" );
      for ( int i = 0; i < myArray.Rank; i++ )
         Console.WriteLine( "{0}:\t{1}\t{2}", i, myArray.GetLowerBound(i), myArray.GetUpperBound(i) );

      // Displays the values of the Array.
      Console.WriteLine( "The Array contains the following values:" );
      PrintValues( myArray );
   }

   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();
   }
}
/*
This code produces the following output.

Bounds:    Lower    Upper
0:    2    4
1:    3    7
The Array contains the following values:
    23    24    25    26    27
    33    34    35    36    37
    43    44    45    46    47
*/
using System;
public class SamplesArray4  {

   public static void Main()  {

      // Creates and initializes a multidimensional Array of type string.
      int[] myLengthsArray = new int[2] { 3, 5 };
      int[] myBoundsArray = new int[2] { 2, 3 };
      Array myArray=Array.CreateInstance( typeof(string), myLengthsArray, myBoundsArray );
      for ( int i = myArray.GetLowerBound(0); i <= myArray.GetUpperBound(0); i++ )
         for ( int j = myArray.GetLowerBound(1); j <= myArray.GetUpperBound(1); j++ )  {
            int[] myIndicesArray = new int[2] { i, j };
            myArray.SetValue( Convert.ToString(i) + j, myIndicesArray );
         }

      // Displays the lower bounds and the upper bounds of each dimension.
      Console.WriteLine( "Bounds:\tLower\tUpper" );
      for ( int i = 0; i < myArray.Rank; i++ )
         Console.WriteLine( "{0}:\t{1}\t{2}", i, myArray.GetLowerBound(i), myArray.GetUpperBound(i) );

      // Displays the values of the Array.
      Console.WriteLine( "The Array contains the following values:" );
      PrintValues( myArray );
   }

   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();
   }
}
/*
This code produces the following output.

Bounds:    Lower    Upper
0:    2    4
1:    3    7
The Array contains the following values:
    23    24    25    26    27
    33    34    35    36    37
    43    44    45    46    47
*/

설명

대부분의 클래스와 달리 는 Array 공용 생성자 대신 메서드를 제공하여 CreateInstance 런타임에 바인딩된 액세스를 허용합니다.

lengthslowerBounds 배열에는 동일한 수의 요소가 있어야 합니다. 배열의 요소 lengths 수는 새 Array의 차원 수와 같아야 합니다.

배열의 lengths 각 요소는 새 Array에서 해당 차원의 길이를 지정해야 합니다.

배열의 lowerBounds 각 요소는 새 Array에서 해당 차원의 하한을 지정해야 합니다. 일반적으로 .NET 클래스 라이브러리 및 많은 프로그래밍 언어는 0이 아닌 하한을 처리하지 않습니다.

참조 형식 요소는 로 초기화 null됩니다. 값 형식 요소는 0으로 초기화됩니다.

이 메서드는 O(n) 작업입니다. 여기서 n 는 의 lengths모든 값의 곱입니다.

참고

모든 언어가 하한이 0이 아닌 배열을 지원하는 것은 아니므로 언어의 배열 형식에 따라 Array 0이 아닌 인스턴스를 캐스팅하지 못할 수 있습니다. 예를 들어 하한이 6인 1차원 정수 배열을 C#의 int[] 형식으로 캐스팅할 수 없습니다. 그러면 InvalidCastException 런타임 중에 "'System.Int32[*]' 형식의 개체를 'System.Int32[]''를 입력할 수 없습니다."라는 메시지가 표시됩니다. 여기서 별표(*)는 0이 아닌 기반 인덱스를 의미합니다. 그러나 를 사용하여 만든 CreateInstance(Type, Int32[], Int32[]) 모든 순위의 0부터 시작하는 배열을 언어의 배열로 캐스팅할 수 있습니다. 예를 들어 이 메서드를 사용하여 만든 2차원 0 기반 정수 배열을 C#의 int[,] 형식으로 캐스팅할 수 있습니다.

적용 대상

CreateInstance(Type, Int32, Int32, Int32)

Source:
Array.cs
Source:
Array.cs
Source:
Array.cs

지정한 Type 및 차원 길이를 가진 인덱스가 0부터 시작하는 삼차원 Array를 만듭니다.

public:
 static Array ^ CreateInstance(Type ^ elementType, int length1, int length2, int length3);
public static Array CreateInstance (Type elementType, int length1, int length2, int length3);
static member CreateInstance : Type * int * int * int -> Array
Public Shared Function CreateInstance (elementType As Type, length1 As Integer, length2 As Integer, length3 As Integer) As Array

매개 변수

elementType
Type

만들 ArrayType입니다.

length1
Int32

만들 Array의 첫 번째 차원 크기입니다.

length2
Int32

만들 Array의 두 번째 차원 크기입니다.

length3
Int32

만들 Array의 세 번째 차원 크기입니다.

반환

지정한 Type 및 각 차원에 대해 지정한 길이를 가진 인덱스가 0부터 시작하는 새 삼차원 Array입니다.

예외

elementType이(가) null인 경우

elementType은 유효한 Type이 아닙니다.

elementType은 지원되지 않습니다. 예를 들면 Void는 지원되지 않습니다.

또는

elementType이 개방형 제네릭 형식인 경우.

length1가 0보다 작은 경우

또는

length2가 0보다 작은 경우

또는

length3가 0보다 작은 경우

예제

다음 코드 예제에서는 3차원 을 만들고 초기화하는 방법을 보여 있습니다 Array.

using namespace System;
void PrintValues( Array^ myArr );
void main()
{
   // Creates and initializes a three-dimensional Array instance of type Object.
   Array^ my3DArray = Array::CreateInstance( Object::typeid, 2, 3, 4 );
   for ( int i = my3DArray->GetLowerBound( 0 ); i <= my3DArray->GetUpperBound( 0 ); i++ )
      for ( int j = my3DArray->GetLowerBound( 1 ); j <= my3DArray->GetUpperBound( 1 ); j++ )
         for ( int k = my3DArray->GetLowerBound( 2 ); k <= my3DArray->GetUpperBound( 2 ); k++ )
            my3DArray->SetValue( String::Concat( "abc", i, j, k ), i, j, k );
   
   // Displays the values of the Array.
   Console::WriteLine(  "The three-dimensional Array instance contains the following values:" );
   PrintValues( my3DArray );
}

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();
}

/*
 This code produces the following output.
 
 The three-dimensional Array instance contains the following values:
     abc000    abc001    abc002    abc003
     abc010    abc011    abc012    abc013
     abc020    abc021    abc022    abc023
     abc100    abc101    abc102    abc103
     abc110    abc111    abc112    abc113
     abc120    abc121    abc122    abc123
 */
open System

let printValues (myArray: Array) =
    let mutable i = 0
    let cols = myArray.GetLength(myArray.Rank - 1)
    for item in myArray do
        if i < cols then
            i <- i + 1
        else
            printfn ""
            i <- 1;
        printf $"\t{item}"
    printfn ""

// Creates and initializes a three-dimensional Array of type Object.
let my3DArray = Array.CreateInstance(typeof<obj>, 2, 3, 4 )
// let my3dArray = Array3D.zeroCreate<obj> 2 3 4

for i = my3DArray.GetLowerBound 0 to my3DArray.GetUpperBound 0 do
    for j = my3DArray.GetLowerBound 1 to my3DArray.GetUpperBound 1 do
        for k = my3DArray.GetLowerBound 2 to my3DArray.GetUpperBound 2 do
            my3DArray.SetValue($"abc{i}{j}{k}", i, j, k)

// Displays the values of the Array.
printfn "The three-dimensional Array contains the following values:"
printValues my3DArray


// This code produces the following output.
//     The three-dimensional Array contains the following values:
//         abc000    abc001    abc002    abc003
//         abc010    abc011    abc012    abc013
//         abc020    abc021    abc022    abc023
//         abc100    abc101    abc102    abc103
//         abc110    abc111    abc112    abc113
//         abc120    abc121    abc122    abc123
using System;
public class SamplesArray2  {

   public static void Main()  {

      // Creates and initializes a three-dimensional Array of type Object.
      Array my3DArray=Array.CreateInstance( typeof(Object), 2, 3, 4 );
      for ( int i = my3DArray.GetLowerBound(0); i <= my3DArray.GetUpperBound(0); i++ )
         for ( int j = my3DArray.GetLowerBound(1); j <= my3DArray.GetUpperBound(1); j++ )
            for ( int k = my3DArray.GetLowerBound(2); k <= my3DArray.GetUpperBound(2); k++ )
               my3DArray.SetValue( "abc" + i + j + k, i, j, k );

      // Displays the values of the Array.
      Console.WriteLine( "The three-dimensional Array contains the following values:" );
      PrintValues( my3DArray );
   }

   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();
   }
}
/*
This code produces the following output.

The three-dimensional Array contains the following values:
    abc000    abc001    abc002    abc003
    abc010    abc011    abc012    abc013
    abc020    abc021    abc022    abc023
    abc100    abc101    abc102    abc103
    abc110    abc111    abc112    abc113
    abc120    abc121    abc122    abc123
*/
Public Class SamplesArray    
    
    Public Shared Sub Main()
        
        ' Creates and initializes a three-dimensional Array of type Object.
        Dim my3DArray As Array = Array.CreateInstance(GetType(Object), 2, 3, 4)
        Dim i As Integer
        For i = my3DArray.GetLowerBound(0) To my3DArray.GetUpperBound(0)
            Dim j As Integer
            For j = my3DArray.GetLowerBound(1) To my3DArray.GetUpperBound(1)
                Dim k As Integer
                For k = my3DArray.GetLowerBound(2) To my3DArray.GetUpperBound(2)
                    my3DArray.SetValue("abc" + i.ToString() _
                       + j.ToString() + k.ToString(), i, j, k)
                Next k 
            Next j
        Next i

        ' Displays the values of the Array.
        Console.WriteLine("The three-dimensional Array contains the " _
           + "following values:")
        PrintValues(my3DArray)
    End Sub
    
    
    Public Shared Sub PrintValues(myArr As Array)
        Dim myEnumerator As System.Collections.IEnumerator = _
           myArr.GetEnumerator()
        Dim i As Integer = 0
        Dim cols As Integer = myArr.GetLength(myArr.Rank - 1)
        While myEnumerator.MoveNext()
            If i < cols Then
                i += 1
            Else
                Console.WriteLine()
                i = 1
            End If
            Console.Write(ControlChars.Tab + "{0}", myEnumerator.Current)
        End While
        Console.WriteLine()
    End Sub
End Class

' This code produces the following output.
' 
' The three-dimensional Array contains the following values:
'     abc000    abc001    abc002    abc003
'     abc010    abc011    abc012    abc013
'     abc020    abc021    abc022    abc023
'     abc100    abc101    abc102    abc103
'     abc110    abc111    abc112    abc113
'     abc120    abc121    abc122    abc123

설명

대부분의 클래스와 달리 는 Array 공용 생성자 대신 메서드를 제공하여 CreateInstance 런타임에 바인딩된 액세스를 허용합니다.

참조 형식 요소는 로 초기화 null됩니다. 값 형식 요소는 0으로 초기화됩니다.

이 메서드는 O(n) 작업입니다. 여기서 n 는 , length2length3length1곱입니다.

F#에서는 Array3D.zeroCreate 함수를 대신 사용할 수 있습니다.

적용 대상