Dizilerde Array.IndexOf Metodu

- Eyüp Sosan
- 5.397
- Başlangıç
Array.IndexOf metodu arama yapılmasını sağlayan bir metoddur.
Array.IndexOf metodu arama yapılmasını sağlayan bir metoddur.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Dizi_İndexOF
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
listBox1.Items.Add("Pazartesi");
listBox1.Items.Add("Salı");
listBox1.Items.Add("Çarşamba");
listBox1.Items.Add("Perşembe");
listBox1.Items.Add("Cuma");
listBox1.Items.Add("Cumartesi");
listBox1.Items.Add("Pazar");
}
private void button1_Click(object sender, EventArgs e)
{
string[] gunler = new string[7];
gunler[0] = "Pazartesi";
gunler[1] = "Salı";
gunler[2] = "Çarşamba";
gunler[3] = "Perşembe";
gunler[4] = "Cuma";
gunler[5] = "Cumartesi";
gunler[6] = "Pazar";
string aranan = textBox1.Text;
int sirano = Array.IndexOf(gunler, aranan);
if (sirano <= -1)
{
MessageBox.Show("Bulunamadı");
}
else
{
MessageBox.Show("Bulundu");
}
}
}
}
Yorum yazabilmek için üye girişi yapmanız gerekiyor!