Asp.Net Dersleri – Asp.Net For Döngüsü Örnekleri

Aşağıda for döngüsü kullanılarak yapılmış asp.net uygulamalarının ekran görüntüleri bulun..
1-

public void A(int a)
{
listBox1.Items.Add(a); 
if (a < 5)
{
A(++a);
}
}
private void 
button1_Click(object 
sender, EventArgs e)
{
A(0);
}


2-

private void button1_Click(object 
sender, EventArgs e)
{
string[] names 
={"Ali","Oya","Can","Cem"};
foreach (string value in names)
{
listBox1.Items.Add(String.Format("{0}
-{1}",value.Substring(0,1),value));
}
}


3-

protected void Button1_Click(object sender, 
EventArgs e)
{
ListBox1.Items.Clear();
Random numbers = new Random();
int[] array = { 1, 2, 3, 4, 5};
for (int i = array.Length; i > 1; i--)
{
int j = numbers.Next(i);
ListBox1.Items.Add("r=" + j.ToString());
int tmp = array[j];
array[j] = array[i - 1];
array[i - 1] = tmp;
}
foreach (int value in array)
{
ListBox1.Items.Add(value.ToString());
}
}


4-

public static int 
Fibonacci(int n)
{
int a = 0;int b = 1;
for (int i = 0; i < n; i++)
{
int temp = a;
a = b;
b = temp + b;
}
return a;
}
private void 
button1_Click(object 
sender, EventArgs e)
{
listBox1.Items.Clear();
for (int i = 0; i < 5; 
i++)
{
listBox1.Items.Add(i+"=
" + Fibonacci(i));
}
}


5-

private void button1_Click(object 
sender, EventArgs e)
{
char[] buffer = new char[5];
for (int i = 0; i < 5; i++)
{
buffer[i] = 'a';
}
string result = new string(buffer);
listBox1.Items.Add(result); 
}


6-

static class Perls
{
public static int _value = 5;
}
private void button1_Click(object 
sender, EventArgs e)
{
for (int i = 0; i < 5; i++)
{
listBox1.Items.Add(++Perls._value);
}
}


7-

static class RandomLetter
{
static Random _random = new 
Random();
public static char GetLetter(int a)
{
char let = (char)('a' + a);
return let;
}
}
private void button1_Click(object sender, 
EventArgs e)
{
for (int i = 0; i < 10; i++)
{
listBox1.Items.Add(RandomLetter.GetLetter(i))
;
}
}

Pin It on Pinterest