Aracılığıyla paylaş


Array.IndexOf Yöntem

Tanım

Belirtilen nesneyi arar ve tek boyutlu bir dizide veya dizideki bir öğe aralığında ilk oluşumunun dizinini döndürür.

Aşırı Yüklemeler

Name Description
IndexOf(Array, Object)

Belirtilen nesneyi arar ve tek boyutlu bir dizide ilk oluşumunun dizinini döndürür.

IndexOf(Array, Object, Int32)

Tek boyutlu bir dizinin öğe aralığında belirtilen nesneyi arar ve ilk oluşumunun dizinini döndürür. Aralık, belirtilen bir dizinden dizinin sonuna kadar uzanır.

IndexOf(Array, Object, Int32, Int32)

Tek boyutlu bir dizinin öğe aralığında belirtilen nesneyi arar ve ifs ilk oluşumunun dizinini döndürür. Aralık, belirtilen sayıda öğe için belirtilen dizinden genişletir.

IndexOf<T>(T[], T, Int32)

Tek boyutlu bir dizinin öğe aralığında belirtilen nesneyi arar ve ilk oluşumunun dizinini döndürür. Aralık, belirtilen bir dizinden dizinin sonuna kadar uzanır.

IndexOf<T>(T[], T, Int32, Int32)

Tek boyutlu bir dizinin öğe aralığında belirtilen nesneyi arar ve ilk oluşumunun dizinini döndürür. Aralık, belirtilen sayıda öğe için belirtilen dizinden genişletir.

IndexOf<T>(T[], T)

Belirtilen nesneyi arar ve tek boyutlu bir dizide ilk oluşumunun dizinini döndürür.

IndexOf(Array, Object)

Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs

Belirtilen nesneyi arar ve tek boyutlu bir dizide ilk oluşumunun dizinini döndürür.

public:
 static int IndexOf(Array ^ array, System::Object ^ value);
public static int IndexOf(Array array, object value);
public static int IndexOf(Array array, object? value);
static member IndexOf : Array * obj -> int
Public Shared Function IndexOf (array As Array, value As Object) As Integer

Parametreler

array
Array

Aranacak tek boyutlu dizi.

value
Object

içinde arraybulunacak nesne.

Döndürülenler

içinde ilk oluşumunun valuearraydizini bulunursa; aksi takdirde dizinin alt sınırı eksi 1 olur.

Özel durumlar

array, null'e eşittir.

array çok boyutludur.

Örnekler

Örnek, dize dizisindeki bir dizenin IndexOf dizinini bulmak için yönteminin aşağıdaki üç aşırı yüklemesini çağırır:

// Create a string array with 3 elements having the same value.
let strings = 
    [| "the"; "quick"; "brown"; "fox"; "jumps"; "over"
       "the"; "lazy"; "dog"; "in"; "the"; "barn" |]

// Display the elements of the array.
printfn "The array contains the following values:"
for i = strings.GetLowerBound 0 to strings.GetUpperBound 0 do
    printfn $"   [{i,2}]: {strings[i]}"

// Search for the first occurrence of the duplicated value.
let searchString = "the"
let index = Array.IndexOf(strings, searchString)
printfn $"The first occurrence of \"{searchString}\" is at index {index}."

// Search for the first occurrence of the duplicated value in the last section of the array.
let index = Array.IndexOf(strings, searchString, 4)
printfn $"The first occurrence of \"{searchString}\" between index 4 and the end is at index {index}."

// Search for the first occurrence of the duplicated value in a section of the array.
let position = index + 1
let index = Array.IndexOf(strings, searchString, position, strings.GetUpperBound 0 - position + 1)
printfn $"The first occurrence of \"{searchString}\" between index {position} and index {strings.GetUpperBound 0} is at index {index}."

// The example displays the following output:
//    The array contains the following values:
//       [ 0]: the
//       [ 1]: quick
//       [ 2]: brown
//       [ 3]: fox
//       [ 4]: jumps
//       [ 5]: over
//       [ 6]: the
//       [ 7]: lazy
//       [ 8]: dog
//       [ 9]: in
//       [10]: the
//       [11]: barn
//    The first occurrence of "the" is at index 0.
//    The first occurrence of "the" between index 4 and the end is at index 6.
//    The first occurrence of "the" between index 7 and index 11 is at index 10.
// Create a string array with 3 elements having the same value.
String[] strings = { "the", "quick", "brown", "fox", "jumps",
                     "over", "the", "lazy", "dog", "in", "the",
                     "barn" };

// Display the elements of the array.
Console.WriteLine("The array contains the following values:");
for (int i = strings.GetLowerBound(0); i <= strings.GetUpperBound(0); i++)
   Console.WriteLine("   [{0,2}]: {1}", i, strings[i]);

// Search for the first occurrence of the duplicated value.
string searchString = "the";
int index = Array.IndexOf(strings, searchString);
Console.WriteLine("The first occurrence of \"{0}\" is at index {1}.",
                  searchString, index);

// Search for the first occurrence of the duplicated value in the last section of the array.
index = Array.IndexOf(strings, searchString, 4);
Console.WriteLine("The first occurrence of \"{0}\" between index 4 and the end is at index {1}.",
                  searchString, index);

// Search for the first occurrence of the duplicated value in a section of the array.
int position = index + 1;
index = Array.IndexOf(strings, searchString, position, strings.GetUpperBound(0) - position + 1);
Console.WriteLine("The first occurrence of \"{0}\" between index {1} and index {2} is at index {3}.",
                  searchString, position, strings.GetUpperBound(0), index);

// The example displays the following output:
//    The array contains the following values:
//       [ 0]: the
//       [ 1]: quick
//       [ 2]: brown
//       [ 3]: fox
//       [ 4]: jumps
//       [ 5]: over
//       [ 6]: the
//       [ 7]: lazy
//       [ 8]: dog
//       [ 9]: in
//       [10]: the
//       [11]: barn
//    The first occurrence of "the" is at index 0.
//    The first occurrence of "the" between index 4 and the end is at index 6.
//    The first occurrence of "the" between index 7 and index 11 is at index 10.
Public Module Example
   Public Sub Main()
      ' Create a string array with 3 elements having the same value.
      Dim strings() As String = { "the", "quick", "brown", "fox",
                                  "jumps", "over", "the", "lazy",
                                  "dog", "in", "the", "barn" }

      ' Display the values of the array.
      Console.WriteLine("The array contains the following values:")
      For i As Integer = strings.GetLowerBound(0) To strings.GetUpperBound(0)
         Console.WriteLine("   [{0,2}]: {1}", i, strings(i))
      Next

      ' Search for the first occurrence of the duplicated value.
      Dim searchString As String = "the"
      Dim index As Integer = Array.IndexOf(strings, searchString)
      Console.WriteLine("The first occurrence of ""{0}"" is at index {1}.",
                        searchString, index)
        
      ' Search for the first occurrence of the duplicated value in the last section of the array.
      index = Array.IndexOf(strings, searchString, 4)
      Console.WriteLine("The first occurrence of ""{0}"" between index 4 and the end is at index {1}.",
                        searchString, index)
        
      ' Search for the first occurrence of the duplicated value in a section of the array.
       Dim position As Integer = index + 1
       index = Array.IndexOf(strings, searchString, position, strings.GetUpperBound(0) - position + 1)
       Console.WriteLine("The first occurrence of ""{0}"" between index {1} and index {2} is at index {3}.",
                         searchString, position, strings.GetUpperBound(0), index)
    End Sub
End Module
' The example displays the following output:
'    The array contains the following values:
'       [ 0]: the
'       [ 1]: quick
'       [ 2]: brown
'       [ 3]: fox
'       [ 4]: jumps
'       [ 5]: over
'       [ 6]: the
'       [ 7]: lazy
'       [ 8]: dog
'       [ 9]: in
'       [10]: the
'       [11]: barn
'    The first occurrence of "the" is at index 0.
'    The first occurrence of "the" between index 4 and the end is at index 6.
'    The first occurrence of "the" between index 7 and index 11 is at index 10.

Açıklamalar

Bu yöntem için tek boyutlu bir dizinin valuetüm öğelerini arar. yönteminde arraymevcut olup olmadığını value belirlemek için, varsayılan eşitlik karşılaştırıcısını EqualityComparer<T>.Defaultkullanarak bir eşitlik karşılaştırması gerçekleştirir.

Çoğu dizi sıfırın alt sınırına sahip olduğundan, bu yöntem genellikle bulunamazsavalue -1 döndürür. Dizinin alt sınırı (0x80000000) değerine eşit Int32.MinValueve value bulunamazsa, bu yöntem döndürür Int32.MaxValue (0x7FFFFFFF).

Bu yöntem bir O(n) işlemidir; burada n değeridir Lengtharray.

Ayrıca bkz.

Şunlara uygulanır

IndexOf(Array, Object, Int32)

Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs

Tek boyutlu bir dizinin öğe aralığında belirtilen nesneyi arar ve ilk oluşumunun dizinini döndürür. Aralık, belirtilen bir dizinden dizinin sonuna kadar uzanır.

public:
 static int IndexOf(Array ^ array, System::Object ^ value, int startIndex);
public static int IndexOf(Array array, object value, int startIndex);
public static int IndexOf(Array array, object? value, int startIndex);
static member IndexOf : Array * obj * int -> int
Public Shared Function IndexOf (array As Array, value As Object, startIndex As Integer) As Integer

Parametreler

array
Array

Aranacak tek boyutlu dizi.

value
Object

içinde arraybulunacak nesne.

startIndex
Int32

Aramanın başlangıç dizini. 0 (sıfır) boş bir dizide geçerlidir.

Döndürülenler

bulunursa, içindeki öğesinden startIndex son öğeye kadar uzanan öğe array aralığında ilk oluşumunun valuedizini; aksi takdirde dizinin alt sınırı eksi 1 olur.

Özel durumlar

array, null'e eşittir.

startIndex için geçerli dizin arrayaralığının dışındadır.

array çok boyutludur.

Örnekler

Örnek, dize dizisindeki bir dizenin IndexOf dizinini bulmak için yönteminin aşağıdaki üç aşırı yüklemesini çağırır:

// Create a string array with 3 elements having the same value.
let strings = 
    [| "the"; "quick"; "brown"; "fox"; "jumps"; "over"
       "the"; "lazy"; "dog"; "in"; "the"; "barn" |]

// Display the elements of the array.
printfn "The array contains the following values:"
for i = strings.GetLowerBound 0 to strings.GetUpperBound 0 do
    printfn $"   [{i,2}]: {strings[i]}"

// Search for the first occurrence of the duplicated value.
let searchString = "the"
let index = Array.IndexOf(strings, searchString)
printfn $"The first occurrence of \"{searchString}\" is at index {index}."

// Search for the first occurrence of the duplicated value in the last section of the array.
let index = Array.IndexOf(strings, searchString, 4)
printfn $"The first occurrence of \"{searchString}\" between index 4 and the end is at index {index}."

// Search for the first occurrence of the duplicated value in a section of the array.
let position = index + 1
let index = Array.IndexOf(strings, searchString, position, strings.GetUpperBound 0 - position + 1)
printfn $"The first occurrence of \"{searchString}\" between index {position} and index {strings.GetUpperBound 0} is at index {index}."

// The example displays the following output:
//    The array contains the following values:
//       [ 0]: the
//       [ 1]: quick
//       [ 2]: brown
//       [ 3]: fox
//       [ 4]: jumps
//       [ 5]: over
//       [ 6]: the
//       [ 7]: lazy
//       [ 8]: dog
//       [ 9]: in
//       [10]: the
//       [11]: barn
//    The first occurrence of "the" is at index 0.
//    The first occurrence of "the" between index 4 and the end is at index 6.
//    The first occurrence of "the" between index 7 and index 11 is at index 10.
// Create a string array with 3 elements having the same value.
String[] strings = { "the", "quick", "brown", "fox", "jumps",
                     "over", "the", "lazy", "dog", "in", "the",
                     "barn" };

// Display the elements of the array.
Console.WriteLine("The array contains the following values:");
for (int i = strings.GetLowerBound(0); i <= strings.GetUpperBound(0); i++)
   Console.WriteLine("   [{0,2}]: {1}", i, strings[i]);

// Search for the first occurrence of the duplicated value.
string searchString = "the";
int index = Array.IndexOf(strings, searchString);
Console.WriteLine("The first occurrence of \"{0}\" is at index {1}.",
                  searchString, index);

// Search for the first occurrence of the duplicated value in the last section of the array.
index = Array.IndexOf(strings, searchString, 4);
Console.WriteLine("The first occurrence of \"{0}\" between index 4 and the end is at index {1}.",
                  searchString, index);

// Search for the first occurrence of the duplicated value in a section of the array.
int position = index + 1;
index = Array.IndexOf(strings, searchString, position, strings.GetUpperBound(0) - position + 1);
Console.WriteLine("The first occurrence of \"{0}\" between index {1} and index {2} is at index {3}.",
                  searchString, position, strings.GetUpperBound(0), index);

// The example displays the following output:
//    The array contains the following values:
//       [ 0]: the
//       [ 1]: quick
//       [ 2]: brown
//       [ 3]: fox
//       [ 4]: jumps
//       [ 5]: over
//       [ 6]: the
//       [ 7]: lazy
//       [ 8]: dog
//       [ 9]: in
//       [10]: the
//       [11]: barn
//    The first occurrence of "the" is at index 0.
//    The first occurrence of "the" between index 4 and the end is at index 6.
//    The first occurrence of "the" between index 7 and index 11 is at index 10.
Public Module Example
   Public Sub Main()
      ' Create a string array with 3 elements having the same value.
      Dim strings() As String = { "the", "quick", "brown", "fox",
                                  "jumps", "over", "the", "lazy",
                                  "dog", "in", "the", "barn" }

      ' Display the values of the array.
      Console.WriteLine("The array contains the following values:")
      For i As Integer = strings.GetLowerBound(0) To strings.GetUpperBound(0)
         Console.WriteLine("   [{0,2}]: {1}", i, strings(i))
      Next

      ' Search for the first occurrence of the duplicated value.
      Dim searchString As String = "the"
      Dim index As Integer = Array.IndexOf(strings, searchString)
      Console.WriteLine("The first occurrence of ""{0}"" is at index {1}.",
                        searchString, index)
        
      ' Search for the first occurrence of the duplicated value in the last section of the array.
      index = Array.IndexOf(strings, searchString, 4)
      Console.WriteLine("The first occurrence of ""{0}"" between index 4 and the end is at index {1}.",
                        searchString, index)
        
      ' Search for the first occurrence of the duplicated value in a section of the array.
       Dim position As Integer = index + 1
       index = Array.IndexOf(strings, searchString, position, strings.GetUpperBound(0) - position + 1)
       Console.WriteLine("The first occurrence of ""{0}"" between index {1} and index {2} is at index {3}.",
                         searchString, position, strings.GetUpperBound(0), index)
    End Sub
End Module
' The example displays the following output:
'    The array contains the following values:
'       [ 0]: the
'       [ 1]: quick
'       [ 2]: brown
'       [ 3]: fox
'       [ 4]: jumps
'       [ 5]: over
'       [ 6]: the
'       [ 7]: lazy
'       [ 8]: dog
'       [ 9]: in
'       [10]: the
'       [11]: barn
'    The first occurrence of "the" is at index 0.
'    The first occurrence of "the" between index 4 and the end is at index 6.
'    The first occurrence of "the" between index 7 and index 11 is at index 10.

Açıklamalar

Bu yöntem, dizindeki startIndex öğesinden son öğeye kadar tek boyutlu bir dizi arar. yönteminde arraymevcut olup olmadığını value belirlemek için, varsayılan eşitlik karşılaştırıcısını EqualityComparer<T>.Defaultkullanarak bir eşitlik karşılaştırması gerçekleştirir.

Çoğu dizi sıfırın alt sınırına sahip olduğundan, bu yöntem genellikle bulunamazsa value -1 döndürür. Dizinin alt sınırı (0x80000000) değerine eşit Int32.MinValueve value bulunamazsa, bu yöntem döndürür Int32.MaxValue (0x7FFFFFFF).

eşitse startIndexArray.Length, yöntemi -1 döndürür. değerinden Array.Lengthbüyükse startIndex yöntemi bir ArgumentOutOfRangeExceptionoluşturur.

Bu yöntem, öğesinden startIndex sonuna kadar olan öğelerin sayısı olan n bir O(n) işlemidirarray.

Ayrıca bkz.

Şunlara uygulanır

IndexOf(Array, Object, Int32, Int32)

Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs

Tek boyutlu bir dizinin öğe aralığında belirtilen nesneyi arar ve ifs ilk oluşumunun dizinini döndürür. Aralık, belirtilen sayıda öğe için belirtilen dizinden genişletir.

public:
 static int IndexOf(Array ^ array, System::Object ^ value, int startIndex, int count);
public static int IndexOf(Array array, object value, int startIndex, int count);
public static int IndexOf(Array array, object? value, int startIndex, int count);
static member IndexOf : Array * obj * int * int -> int
Public Shared Function IndexOf (array As Array, value As Object, startIndex As Integer, count As Integer) As Integer

Parametreler

array
Array

Aranacak tek boyutlu dizi.

value
Object

içinde arraybulunacak nesne.

startIndex
Int32

Aramanın başlangıç dizini. 0 (sıfır) boş bir dizide geçerlidir.

count
Int32

Aranacak öğe sayısı.

Döndürülenler

dizininden - 1'e + startIndexcount kadar olan dizininde array bulunursa, ilk oluşumunun valuedizinistartIndex; aksi takdirde dizinin alt sınırı eksi 1 olur.

Özel durumlar

array, null'e eşittir.

startIndex için geçerli dizin arrayaralığının dışındadır.

-veya-

count, sıfırdan küçüktür.

-veya-

startIndex ve count içinde arraygeçerli bir bölüm belirtmeyin.

array çok boyutludur.

Örnekler

Örnek, dize dizisindeki bir dizenin IndexOf dizinini bulmak için yönteminin aşağıdaki üç aşırı yüklemesini çağırır:

  • IndexOf(Array, Object), dize dizisinde "the" dizesinin ilk oluşumunu belirlemek için.

  • IndexOf(Array, Object, Int32), dize dizisinin dördüncü öğesinde "the" dizesinin ilk oluşumunu belirlemek için.

  • IndexOf(Array, Object, Int32, Int32), dize dizisinde "the" dizesinin, dizinin sonundaki son başarılı eşleşmeyi izleyen öğeden ilk oluşumunu belirlemek için. Bağımsız değişkenin count değerini belirlemek için dizinin üst sınırlarını başlangıç dizininden çıkarır ve bir tane ekler.

// Create a string array with 3 elements having the same value.
let strings = 
    [| "the"; "quick"; "brown"; "fox"; "jumps"; "over"
       "the"; "lazy"; "dog"; "in"; "the"; "barn" |]

// Display the elements of the array.
printfn "The array contains the following values:"
for i = strings.GetLowerBound 0 to strings.GetUpperBound 0 do
    printfn $"   [{i,2}]: {strings[i]}"

// Search for the first occurrence of the duplicated value.
let searchString = "the"
let index = Array.IndexOf(strings, searchString)
printfn $"The first occurrence of \"{searchString}\" is at index {index}."

// Search for the first occurrence of the duplicated value in the last section of the array.
let index = Array.IndexOf(strings, searchString, 4)
printfn $"The first occurrence of \"{searchString}\" between index 4 and the end is at index {index}."

// Search for the first occurrence of the duplicated value in a section of the array.
let position = index + 1
let index = Array.IndexOf(strings, searchString, position, strings.GetUpperBound 0 - position + 1)
printfn $"The first occurrence of \"{searchString}\" between index {position} and index {strings.GetUpperBound 0} is at index {index}."

// The example displays the following output:
//    The array contains the following values:
//       [ 0]: the
//       [ 1]: quick
//       [ 2]: brown
//       [ 3]: fox
//       [ 4]: jumps
//       [ 5]: over
//       [ 6]: the
//       [ 7]: lazy
//       [ 8]: dog
//       [ 9]: in
//       [10]: the
//       [11]: barn
//    The first occurrence of "the" is at index 0.
//    The first occurrence of "the" between index 4 and the end is at index 6.
//    The first occurrence of "the" between index 7 and index 11 is at index 10.
// Create a string array with 3 elements having the same value.
String[] strings = { "the", "quick", "brown", "fox", "jumps",
                     "over", "the", "lazy", "dog", "in", "the",
                     "barn" };

// Display the elements of the array.
Console.WriteLine("The array contains the following values:");
for (int i = strings.GetLowerBound(0); i <= strings.GetUpperBound(0); i++)
   Console.WriteLine("   [{0,2}]: {1}", i, strings[i]);

// Search for the first occurrence of the duplicated value.
string searchString = "the";
int index = Array.IndexOf(strings, searchString);
Console.WriteLine("The first occurrence of \"{0}\" is at index {1}.",
                  searchString, index);

// Search for the first occurrence of the duplicated value in the last section of the array.
index = Array.IndexOf(strings, searchString, 4);
Console.WriteLine("The first occurrence of \"{0}\" between index 4 and the end is at index {1}.",
                  searchString, index);

// Search for the first occurrence of the duplicated value in a section of the array.
int position = index + 1;
index = Array.IndexOf(strings, searchString, position, strings.GetUpperBound(0) - position + 1);
Console.WriteLine("The first occurrence of \"{0}\" between index {1} and index {2} is at index {3}.",
                  searchString, position, strings.GetUpperBound(0), index);

// The example displays the following output:
//    The array contains the following values:
//       [ 0]: the
//       [ 1]: quick
//       [ 2]: brown
//       [ 3]: fox
//       [ 4]: jumps
//       [ 5]: over
//       [ 6]: the
//       [ 7]: lazy
//       [ 8]: dog
//       [ 9]: in
//       [10]: the
//       [11]: barn
//    The first occurrence of "the" is at index 0.
//    The first occurrence of "the" between index 4 and the end is at index 6.
//    The first occurrence of "the" between index 7 and index 11 is at index 10.
Public Module Example
   Public Sub Main()
      ' Create a string array with 3 elements having the same value.
      Dim strings() As String = { "the", "quick", "brown", "fox",
                                  "jumps", "over", "the", "lazy",
                                  "dog", "in", "the", "barn" }

      ' Display the values of the array.
      Console.WriteLine("The array contains the following values:")
      For i As Integer = strings.GetLowerBound(0) To strings.GetUpperBound(0)
         Console.WriteLine("   [{0,2}]: {1}", i, strings(i))
      Next

      ' Search for the first occurrence of the duplicated value.
      Dim searchString As String = "the"
      Dim index As Integer = Array.IndexOf(strings, searchString)
      Console.WriteLine("The first occurrence of ""{0}"" is at index {1}.",
                        searchString, index)
        
      ' Search for the first occurrence of the duplicated value in the last section of the array.
      index = Array.IndexOf(strings, searchString, 4)
      Console.WriteLine("The first occurrence of ""{0}"" between index 4 and the end is at index {1}.",
                        searchString, index)
        
      ' Search for the first occurrence of the duplicated value in a section of the array.
       Dim position As Integer = index + 1
       index = Array.IndexOf(strings, searchString, position, strings.GetUpperBound(0) - position + 1)
       Console.WriteLine("The first occurrence of ""{0}"" between index {1} and index {2} is at index {3}.",
                         searchString, position, strings.GetUpperBound(0), index)
    End Sub
End Module
' The example displays the following output:
'    The array contains the following values:
'       [ 0]: the
'       [ 1]: quick
'       [ 2]: brown
'       [ 3]: fox
'       [ 4]: jumps
'       [ 5]: over
'       [ 6]: the
'       [ 7]: lazy
'       [ 8]: dog
'       [ 9]: in
'       [10]: the
'       [11]: barn
'    The first occurrence of "the" is at index 0.
'    The first occurrence of "the" between index 4 and the end is at index 6.
'    The first occurrence of "the" between index 7 and index 11 is at index 10.

Açıklamalar

Bu yöntem, 0'dan büyükse count tek boyutlu bir dizinin öğelerini artı eksi 1'e countstartIndexstartIndex kadar arar. yönteminde arraymevcut olup olmadığını value belirlemek için, varsayılan eşitlik karşılaştırıcısını EqualityComparer<T>.Defaultkullanarak bir eşitlik karşılaştırması gerçekleştirir.

Çoğu dizi sıfırın alt sınırına sahip olduğundan, bu yöntem genellikle bulunamadığında value -1 döndürür. Dizinin alt sınırı (0x80000000) değerine eşit Int32.MinValue ve value bulunamazsa, bu yöntem döndürür Int32.MaxValue (0x7FFFFFFF).

eşitse startindexArray.Length, yöntemi -1 döndürür. değerinden Array.Lengthbüyükse startIndex yöntemi bir ArgumentOutOfRangeExceptionoluşturur.

Bu yöntem bir O(n) işlemidir; burada n olur count.

Ayrıca bkz.

Şunlara uygulanır

IndexOf<T>(T[], T, Int32)

Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs

Tek boyutlu bir dizinin öğe aralığında belirtilen nesneyi arar ve ilk oluşumunun dizinini döndürür. Aralık, belirtilen bir dizinden dizinin sonuna kadar uzanır.

public:
generic <typename T>
 static int IndexOf(cli::array <T> ^ array, T value, int startIndex);
public static int IndexOf<T>(T[] array, T value, int startIndex);
static member IndexOf : 'T[] * 'T * int -> int
Public Shared Function IndexOf(Of T) (array As T(), value As T, startIndex As Integer) As Integer

Tür Parametreleri

T

Dizinin öğelerinin türü.

Parametreler

array
T[]

Aranacak tek boyutlu, sıfır tabanlı dizi.

value
T

içinde arraybulunacak nesne.

startIndex
Int32

Aramanın sıfır tabanlı başlangıç dizini. 0 (sıfır) boş bir dizide geçerlidir.

Döndürülenler

içindeki öğe array aralığındaki ilk oluşumununvalue, bulunursa son öğeye startIndex kadar uzanan sıfır tabanlı dizini; aksi takdirde -1.

Özel durumlar

array, null'e eşittir.

startIndex için geçerli dizin arrayaralığının dışındadır.

Örnekler

Aşağıdaki örnek, yönteminin üç genel aşırı yüklemesini IndexOf de gösterir. Dizin konumu 0 ve dizin konumu 5'te iki kez görüntülenen bir girişle bir dize dizisi oluşturulur. IndexOf<T>(T[], T) yöntemi aşırı yüklemesi diziyi baştan arar ve dizenin ilk oluşumunu bulur. IndexOf<T>(T[], T, Int32) Yöntem aşırı yüklemesi, dizin konumu 3'le başlayan ve dizinin sonuna devam eden dizide arama yapmak için kullanılır ve dizenin ikinci oluşumunu bulur. Son olarak, IndexOf<T>(T[], T, Int32, Int32) yöntem aşırı yüklemesi, iki dizin konumundan başlayarak iki girdiden oluşan bir aralığı aramak için kullanılır; bu aralıkta arama dizesi örneği olmadığından -1 döndürür.

string[] dinosaurs = { "Tyrannosaurus",
    "Amargasaurus",
    "Mamenchisaurus",
    "Brachiosaurus",
    "Deinonychus",
    "Tyrannosaurus",
    "Compsognathus" };

Console.WriteLine();
foreach(string dinosaur in dinosaurs)
{
    Console.WriteLine(dinosaur);
}

Console.WriteLine(
    "\nArray.IndexOf(dinosaurs, \"Tyrannosaurus\"): {0}",
    Array.IndexOf(dinosaurs, "Tyrannosaurus"));

Console.WriteLine(
    "\nArray.IndexOf(dinosaurs, \"Tyrannosaurus\", 3): {0}",
    Array.IndexOf(dinosaurs, "Tyrannosaurus", 3));

Console.WriteLine(
    "\nArray.IndexOf(dinosaurs, \"Tyrannosaurus\", 2, 2): {0}",
    Array.IndexOf(dinosaurs, "Tyrannosaurus", 2, 2));

/* This code example produces the following output:

Tyrannosaurus
Amargasaurus
Mamenchisaurus
Brachiosaurus
Deinonychus
Tyrannosaurus
Compsognathus

Array.IndexOf(dinosaurs, "Tyrannosaurus"): 0

Array.IndexOf(dinosaurs, "Tyrannosaurus", 3): 5

Array.IndexOf(dinosaurs, "Tyrannosaurus", 2, 2): -1
*/
open System

let dinosaurs =
    [| "Tyrannosaurus"
       "Amargasaurus"
       "Mamenchisaurus"
       "Brachiosaurus"
       "Deinonychus"
       "Tyrannosaurus"
       "Compsognathus" |]

printfn ""
for dino in dinosaurs do
    printfn $"{dino}"

Array.IndexOf(dinosaurs, "Tyrannosaurus")
|> printfn "\nArray.IndexOf(dinosaurs, \"Tyrannosaurus\"): %i"

Array.IndexOf(dinosaurs, "Tyrannosaurus", 3)
|> printfn "\nArray.IndexOf(dinosaurs, \"Tyrannosaurus\", 3): %i"

Array.IndexOf(dinosaurs, "Tyrannosaurus", 2, 2)
|> printfn "\nArray.IndexOf(dinosaurs, \"Tyrannosaurus\", 2, 2): %i"

// This code example produces the following output:
//
//    Tyrannosaurus
//    Amargasaurus
//    Mamenchisaurus
//    Brachiosaurus
//    Deinonychus
//    Tyrannosaurus
//    Compsognathus
//    
//    Array.IndexOf(dinosaurs, "Tyrannosaurus"): 0
//
//    Array.IndexOf(dinosaurs, "Tyrannosaurus", 3): 5
//
//    Array.IndexOf(dinosaurs, "Tyrannosaurus", 2, 2): -1
Public Class Example

    Public Shared Sub Main()

        Dim dinosaurs() As String = { "Tyrannosaurus", _
            "Amargasaurus", _
            "Mamenchisaurus", _
            "Brachiosaurus", _
            "Deinonychus", _
            "Tyrannosaurus", _
            "Compsognathus" }

        Console.WriteLine()
        For Each dinosaur As String In dinosaurs
            Console.WriteLine(dinosaur)
        Next

        Console.WriteLine(vbLf & _
            "Array.IndexOf(dinosaurs, ""Tyrannosaurus""): {0}", _
            Array.IndexOf(dinosaurs, "Tyrannosaurus"))

        Console.WriteLine(vbLf & _
            "Array.IndexOf(dinosaurs, ""Tyrannosaurus"", 3): {0}", _
            Array.IndexOf(dinosaurs, "Tyrannosaurus", 3))

        Console.WriteLine(vbLf & _
            "Array.IndexOf(dinosaurs, ""Tyrannosaurus"", 2, 2): {0}", _
            Array.IndexOf(dinosaurs, "Tyrannosaurus", 2, 2))

    End Sub
End Class

' This code example produces the following output:
'
'Tyrannosaurus
'Amargasaurus
'Mamenchisaurus
'Brachiosaurus
'Deinonychus
'Tyrannosaurus
'Compsognathus
'
'Array.IndexOf(dinosaurs, "Tyrannosaurus"): 0
'
'Array.IndexOf(dinosaurs, "Tyrannosaurus", 3): 5
'
'Array.IndexOf(dinosaurs, "Tyrannosaurus", 2, 2): -1

Açıklamalar

Bu yöntem, dizinin sonundaki öğesinden startIndex tek boyutlu bir diziyi arar. yönteminde arraymevcut olup olmadığını value belirlemek için, varsayılan eşitlik karşılaştırıcısını EqualityComparer<T>.Defaultkullanarak bir eşitlik karşılaştırması gerçekleştirir.

eşitse startIndexLength, yöntemi -1 döndürür. değerinden Array.Lengthbüyükse startIndex yöntemi bir ArgumentOutOfRangeExceptionoluşturur.

Bu yöntem, öğesinden startIndex sonuna kadar olan öğelerin sayısı olan n bir O(n) işlemidirarray.

Ayrıca bkz.

Şunlara uygulanır

IndexOf<T>(T[], T, Int32, Int32)

Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs

Tek boyutlu bir dizinin öğe aralığında belirtilen nesneyi arar ve ilk oluşumunun dizinini döndürür. Aralık, belirtilen sayıda öğe için belirtilen dizinden genişletir.

public:
generic <typename T>
 static int IndexOf(cli::array <T> ^ array, T value, int startIndex, int count);
public static int IndexOf<T>(T[] array, T value, int startIndex, int count);
static member IndexOf : 'T[] * 'T * int * int -> int
Public Shared Function IndexOf(Of T) (array As T(), value As T, startIndex As Integer, count As Integer) As Integer

Tür Parametreleri

T

Dizinin öğelerinin türü.

Parametreler

array
T[]

Aranacak tek boyutlu, sıfır tabanlı dizi.

value
T

içinde arraybulunacak nesne.

startIndex
Int32

Aramanın sıfır tabanlı başlangıç dizini. 0 (sıfır) boş bir dizide geçerlidir.

count
Int32

Bölümde aranacak öğe sayısı.

Döndürülenler

öğesinde başlayan startIndex ve içinde belirtilen countöğe sayısını içeren öğe array aralığındaki ilk oluşumunun value sıfır tabanlı dizini; aksi takdirde - 1.

Özel durumlar

array, null'e eşittir.

startIndex için geçerli dizin arrayaralığının dışındadır.

-veya-

count, sıfırdan küçüktür.

-veya-

startIndex ve count içinde arraygeçerli bir bölüm belirtmeyin.

Örnekler

Aşağıdaki örnek, yönteminin üç genel aşırı yüklemesini IndexOf de gösterir. Dizin konumu 0 ve dizin konumu 5'te iki kez görüntülenen bir girişle bir dize dizisi oluşturulur. IndexOf<T>(T[], T) yöntemi aşırı yüklemesi diziyi baştan arar ve dizenin ilk oluşumunu bulur. IndexOf<T>(T[], T, Int32) Yöntem aşırı yüklemesi, dizin konumu 3'le başlayan ve dizinin sonuna devam eden dizide arama yapmak için kullanılır ve dizenin ikinci oluşumunu bulur. Son olarak, IndexOf<T>(T[], T, Int32, Int32) yöntem aşırı yüklemesi, iki dizin konumundan başlayarak iki girdiden oluşan bir aralığı aramak için kullanılır; bu aralıkta arama dizesi örneği olmadığından -1 döndürür.

string[] dinosaurs = { "Tyrannosaurus",
    "Amargasaurus",
    "Mamenchisaurus",
    "Brachiosaurus",
    "Deinonychus",
    "Tyrannosaurus",
    "Compsognathus" };

Console.WriteLine();
foreach(string dinosaur in dinosaurs)
{
    Console.WriteLine(dinosaur);
}

Console.WriteLine(
    "\nArray.IndexOf(dinosaurs, \"Tyrannosaurus\"): {0}",
    Array.IndexOf(dinosaurs, "Tyrannosaurus"));

Console.WriteLine(
    "\nArray.IndexOf(dinosaurs, \"Tyrannosaurus\", 3): {0}",
    Array.IndexOf(dinosaurs, "Tyrannosaurus", 3));

Console.WriteLine(
    "\nArray.IndexOf(dinosaurs, \"Tyrannosaurus\", 2, 2): {0}",
    Array.IndexOf(dinosaurs, "Tyrannosaurus", 2, 2));

/* This code example produces the following output:

Tyrannosaurus
Amargasaurus
Mamenchisaurus
Brachiosaurus
Deinonychus
Tyrannosaurus
Compsognathus

Array.IndexOf(dinosaurs, "Tyrannosaurus"): 0

Array.IndexOf(dinosaurs, "Tyrannosaurus", 3): 5

Array.IndexOf(dinosaurs, "Tyrannosaurus", 2, 2): -1
*/
open System

let dinosaurs =
    [| "Tyrannosaurus"
       "Amargasaurus"
       "Mamenchisaurus"
       "Brachiosaurus"
       "Deinonychus"
       "Tyrannosaurus"
       "Compsognathus" |]

printfn ""
for dino in dinosaurs do
    printfn $"{dino}"

Array.IndexOf(dinosaurs, "Tyrannosaurus")
|> printfn "\nArray.IndexOf(dinosaurs, \"Tyrannosaurus\"): %i"

Array.IndexOf(dinosaurs, "Tyrannosaurus", 3)
|> printfn "\nArray.IndexOf(dinosaurs, \"Tyrannosaurus\", 3): %i"

Array.IndexOf(dinosaurs, "Tyrannosaurus", 2, 2)
|> printfn "\nArray.IndexOf(dinosaurs, \"Tyrannosaurus\", 2, 2): %i"

// This code example produces the following output:
//
//    Tyrannosaurus
//    Amargasaurus
//    Mamenchisaurus
//    Brachiosaurus
//    Deinonychus
//    Tyrannosaurus
//    Compsognathus
//    
//    Array.IndexOf(dinosaurs, "Tyrannosaurus"): 0
//
//    Array.IndexOf(dinosaurs, "Tyrannosaurus", 3): 5
//
//    Array.IndexOf(dinosaurs, "Tyrannosaurus", 2, 2): -1
Public Class Example

    Public Shared Sub Main()

        Dim dinosaurs() As String = { "Tyrannosaurus", _
            "Amargasaurus", _
            "Mamenchisaurus", _
            "Brachiosaurus", _
            "Deinonychus", _
            "Tyrannosaurus", _
            "Compsognathus" }

        Console.WriteLine()
        For Each dinosaur As String In dinosaurs
            Console.WriteLine(dinosaur)
        Next

        Console.WriteLine(vbLf & _
            "Array.IndexOf(dinosaurs, ""Tyrannosaurus""): {0}", _
            Array.IndexOf(dinosaurs, "Tyrannosaurus"))

        Console.WriteLine(vbLf & _
            "Array.IndexOf(dinosaurs, ""Tyrannosaurus"", 3): {0}", _
            Array.IndexOf(dinosaurs, "Tyrannosaurus", 3))

        Console.WriteLine(vbLf & _
            "Array.IndexOf(dinosaurs, ""Tyrannosaurus"", 2, 2): {0}", _
            Array.IndexOf(dinosaurs, "Tyrannosaurus", 2, 2))

    End Sub
End Class

' This code example produces the following output:
'
'Tyrannosaurus
'Amargasaurus
'Mamenchisaurus
'Brachiosaurus
'Deinonychus
'Tyrannosaurus
'Compsognathus
'
'Array.IndexOf(dinosaurs, "Tyrannosaurus"): 0
'
'Array.IndexOf(dinosaurs, "Tyrannosaurus", 3): 5
'
'Array.IndexOf(dinosaurs, "Tyrannosaurus", 2, 2): -1

Açıklamalar

Bu yöntem, 0'dan büyükse count tek boyutlu bir dizinin öğelerini artı eksi 1'e countstartIndexstartIndex kadar arar. yönteminde arraymevcut olup olmadığını value belirlemek için, varsayılan eşitlik karşılaştırıcısını EqualityComparer<T>.Defaultkullanarak bir eşitlik karşılaştırması gerçekleştirir.

eşitse startIndexArray.Length, yöntemi -1 döndürür. değerinden Array.Lengthbüyükse startIndex yöntemi bir ArgumentOutOfRangeExceptionoluşturur.

Bu yöntem bir O(n) işlemidir; burada n olur count.

Ayrıca bkz.

Şunlara uygulanır

IndexOf<T>(T[], T)

Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs
Kaynak:
Array.cs

Belirtilen nesneyi arar ve tek boyutlu bir dizide ilk oluşumunun dizinini döndürür.

public:
generic <typename T>
 static int IndexOf(cli::array <T> ^ array, T value);
public static int IndexOf<T>(T[] array, T value);
static member IndexOf : 'T[] * 'T -> int
Public Shared Function IndexOf(Of T) (array As T(), value As T) As Integer

Tür Parametreleri

T

Dizinin öğelerinin türü.

Parametreler

array
T[]

Aranacak tek boyutlu, sıfır tabanlı dizi.

value
T

içinde arraybulunacak nesne.

Döndürülenler

tüm içinde arrayilk oluşumunun value sıfır tabanlı dizini, bulunursa, aksi takdirde -1.

Özel durumlar

array, null'e eşittir.

Örnekler

Aşağıdaki örnek, yönteminin üç genel aşırı yüklemesini IndexOf de gösterir. Dizin konumu 0 ve dizin konumu 5'te iki kez görüntülenen bir girişle bir dize dizisi oluşturulur. IndexOf<T>(T[], T) yöntemi aşırı yüklemesi diziyi baştan arar ve dizenin ilk oluşumunu bulur. IndexOf<T>(T[], T, Int32) Yöntem aşırı yüklemesi, dizin konumu 3'le başlayan ve dizinin sonuna devam eden dizide arama yapmak için kullanılır ve dizenin ikinci oluşumunu bulur. Son olarak, IndexOf<T>(T[], T, Int32, Int32) yöntem aşırı yüklemesi, iki dizin konumundan başlayarak iki girdiden oluşan bir aralığı aramak için kullanılır; bu aralıkta arama dizesi örneği olmadığından -1 döndürür.

string[] dinosaurs = { "Tyrannosaurus",
    "Amargasaurus",
    "Mamenchisaurus",
    "Brachiosaurus",
    "Deinonychus",
    "Tyrannosaurus",
    "Compsognathus" };

Console.WriteLine();
foreach(string dinosaur in dinosaurs)
{
    Console.WriteLine(dinosaur);
}

Console.WriteLine(
    "\nArray.IndexOf(dinosaurs, \"Tyrannosaurus\"): {0}",
    Array.IndexOf(dinosaurs, "Tyrannosaurus"));

Console.WriteLine(
    "\nArray.IndexOf(dinosaurs, \"Tyrannosaurus\", 3): {0}",
    Array.IndexOf(dinosaurs, "Tyrannosaurus", 3));

Console.WriteLine(
    "\nArray.IndexOf(dinosaurs, \"Tyrannosaurus\", 2, 2): {0}",
    Array.IndexOf(dinosaurs, "Tyrannosaurus", 2, 2));

/* This code example produces the following output:

Tyrannosaurus
Amargasaurus
Mamenchisaurus
Brachiosaurus
Deinonychus
Tyrannosaurus
Compsognathus

Array.IndexOf(dinosaurs, "Tyrannosaurus"): 0

Array.IndexOf(dinosaurs, "Tyrannosaurus", 3): 5

Array.IndexOf(dinosaurs, "Tyrannosaurus", 2, 2): -1
*/
open System

let dinosaurs =
    [| "Tyrannosaurus"
       "Amargasaurus"
       "Mamenchisaurus"
       "Brachiosaurus"
       "Deinonychus"
       "Tyrannosaurus"
       "Compsognathus" |]

printfn ""
for dino in dinosaurs do
    printfn $"{dino}"

Array.IndexOf(dinosaurs, "Tyrannosaurus")
|> printfn "\nArray.IndexOf(dinosaurs, \"Tyrannosaurus\"): %i"

Array.IndexOf(dinosaurs, "Tyrannosaurus", 3)
|> printfn "\nArray.IndexOf(dinosaurs, \"Tyrannosaurus\", 3): %i"

Array.IndexOf(dinosaurs, "Tyrannosaurus", 2, 2)
|> printfn "\nArray.IndexOf(dinosaurs, \"Tyrannosaurus\", 2, 2): %i"

// This code example produces the following output:
//
//    Tyrannosaurus
//    Amargasaurus
//    Mamenchisaurus
//    Brachiosaurus
//    Deinonychus
//    Tyrannosaurus
//    Compsognathus
//    
//    Array.IndexOf(dinosaurs, "Tyrannosaurus"): 0
//
//    Array.IndexOf(dinosaurs, "Tyrannosaurus", 3): 5
//
//    Array.IndexOf(dinosaurs, "Tyrannosaurus", 2, 2): -1
Public Class Example

    Public Shared Sub Main()

        Dim dinosaurs() As String = { "Tyrannosaurus", _
            "Amargasaurus", _
            "Mamenchisaurus", _
            "Brachiosaurus", _
            "Deinonychus", _
            "Tyrannosaurus", _
            "Compsognathus" }

        Console.WriteLine()
        For Each dinosaur As String In dinosaurs
            Console.WriteLine(dinosaur)
        Next

        Console.WriteLine(vbLf & _
            "Array.IndexOf(dinosaurs, ""Tyrannosaurus""): {0}", _
            Array.IndexOf(dinosaurs, "Tyrannosaurus"))

        Console.WriteLine(vbLf & _
            "Array.IndexOf(dinosaurs, ""Tyrannosaurus"", 3): {0}", _
            Array.IndexOf(dinosaurs, "Tyrannosaurus", 3))

        Console.WriteLine(vbLf & _
            "Array.IndexOf(dinosaurs, ""Tyrannosaurus"", 2, 2): {0}", _
            Array.IndexOf(dinosaurs, "Tyrannosaurus", 2, 2))

    End Sub
End Class

' This code example produces the following output:
'
'Tyrannosaurus
'Amargasaurus
'Mamenchisaurus
'Brachiosaurus
'Deinonychus
'Tyrannosaurus
'Compsognathus
'
'Array.IndexOf(dinosaurs, "Tyrannosaurus"): 0
'
'Array.IndexOf(dinosaurs, "Tyrannosaurus", 3): 5
'
'Array.IndexOf(dinosaurs, "Tyrannosaurus", 2, 2): -1

Açıklamalar

Bu yöntem için tek boyutlu bir dizinin valuetüm öğelerini arar. yönteminde arraymevcut olup olmadığını value belirlemek için, varsayılan eşitlik karşılaştırıcısını EqualityComparer<T>.Defaultkullanarak bir eşitlik karşılaştırması gerçekleştirir.

Bu yöntem bir O(n) işlemidir; burada n değeridir Lengtharray.

Ayrıca bkz.

Şunlara uygulanır