Örnek
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp7
{
class Program
{
static void Main(string[] args)
{
int[] dizi = new int[10];
for (int i = 0; i < dizi.Length; i++)
{
dizi[i] = 2 + 2 * i;
}
for (int i = 0; i < dizi.Length; i++)
{
Console.WriteLine(dizi[i]);
}
Console.ReadKey();
}
}
}
foreach Yapısı
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp7
{
class Program
{
static void Main(string[] args)
{
int[] dizi = { 45, 65, 85, 1, 10, 20, 50 };
int toplam = 0;
foreach (int rakam in dizi)
{
Console.WriteLine(rakam);
}
foreach (int rakam in dizi)
{
toplam = toplam + rakam;
}
Console.WriteLine(toplam);
Console.ReadKey();
}
}
}
Örnek
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int[] array = {1,2,3,4,5,6,7,8};
label1.Text = array[3].ToString();
}
}
}
Örnek
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string[] isimler = new string[5];
int sayac = 0;
private void button1_Click(object sender, EventArgs e)
{
isimler[sayac] = textBox1.Text;
sayac++;
if (sayac == 5)
{
sayac = 0;
}
label1.Text = (sayac + 1) + ". ismi giriniz";
textBox1.Clear();
textBox1.Focus();
}
private void button2_Click(object sender, EventArgs e)
{
for (int i = 0; i < isimler.Length; i++)
{
listBox1.Items.Add(isimler[i]);
}
}
}
}
Örnek
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp8
{
class Program
{
static void Main(string[] args)
{
int[] fib = new int[10];
fib[0] = 1;
fib[1] = 1;
for (int i = 2; i < fib.Length; i++)
{
fib[i] = fib[i - 2] + fib[i - 1];
}
// for (int i = 0; i < fib.Length; i++) yorum satırı
foreach (int i in fib)
{
Console.Write(" " + i);
}
Console.ReadKey();
}
}
}