SORU
23 EKİM 2011, Pazar


Eğer string bir dizi değeri içeriyorsa, kontrol, ve eğer öyleyse, konumu elde

Bu dize dizisi var:

string[] stringArray = { "text1", "text2", "text3", "text4" };
string value = "text3";

stringArray value varsa tespit etmek istiyorum. Eğer öyleyse, dizinin konumunu bulmak istiyorum.

Döngüler kullanmak istemiyorum. Herkes bunu nasıl önerebilirsiniz?

CEVAP
23 EKİM 2011, Pazar


Array.IndexOf yöntemi kullanabilirsiniz:

string[] stringArray = { "text1", "text2", "text3", "text4" };
string value = "text3";
int pos = Array.IndexOf(stringArray, value);
if (pos > -1)
{
    // the array contains the string and the pos variable
    // will have its position in the array
}

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • eHow

    eHow

    27 NİSAN 2006
  • How It Should Have Ended

    How It Shoul

    5 Mart 2007
  • jcortes187

    jcortes187

    24 Mart 2006