Professional Documents
Culture Documents
Bölüm
C#'A GİRİŞ 1
1. Editörün tanıtılması
2. Konsol uygulaması
ornek1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ornek1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Merhaba");
Console.ReadLine();
}
}
}
Namespace: .NET framework olarak isimlendirilen sınıf kitaplığındaki sınıfların saklandığı yapılardır.
Class: sınıf
WriteLine: Ekrana yazdırıp alt satıra geç (Write)
ReadLine: Ekrandan okuma (Read, ReadKey)
3. Form uygulaması
ornek2
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 ornek2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Visual Studio ile hazırlanan C# projeleri için otomatik olarak “Program.cs” kodu üretilmekte ve
programlar buradaki “Main()” metodundan itibaren çalışmaya başlamaktadırlar. Burada Application
sınıfının Run metodunda projenin başlangıç formunun ismi verilmektedir.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace ornek2
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
4. Tanımlayıcılar
İsimlendirme kuralları: Sadece harf, rakam veya altçizgi // harf veya altçizgi ile başlamalı // 77 tane
anahtar sözcük kullanılamaz
5. Değişkenler
.NET uyumlu her programlama dili Common Type System (ortak tip sistemi) kurallarına bağlı kalmak
zorundadır.
Değişken bildirimi:
Tip değişken adı;
System.Byte.MinValue
System.Byte.MaxValue
Ornek4
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;
using gercel = System.Single;
namespace ornek4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public gercel x = 1000f;
private void button1_Click(object sender, EventArgs e)
{
byte a;
System.Int32 b=100;
gercel c;
string d;
char z = 'A';
const float pi = 22/7;
var y="Elektronik";
string yol = "C:\\A\\b.dat";
string yol1 = @"C:\A\b.dat";
textBox1.Text = y.ToString(); //y.GetType().ToString();
}
değişken.ToString()
Convert.
ToByte(…)
ToSbyte
ToInt16
ToInt32
ToInt64
ToUInt16
ToUInt32
ToUInt64
ToSingle
ToDouble
ToChar
ToString
ToBoolean
ToDecimal
ToDateTime
ToBase64String
ToBase64CharArray
Ornek5
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 ornek5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Parse
System.Single.Parse(…)
…
Ornek6
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 ornek6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Dizi tanımlamak:
6. Operatörler
Matematiksel
Operatör Açıklama
+ Toplama
- Çıkarma
* Çarpma
/ Bölme
% Kalan
++ Arttırma
-- Azaltma
+= Topla-aktar
-= Çıkar-aktar
*= Çarp-aktar
/= Böl-aktar
Karşılaştırma
Operatör Açıklama
== Eşit
!= Eşit değil
> Büyük
< Küçük
>= Büyük eşit
<= Küçük eşit
Mantıksal
Operatör Açıklama
&& VE
|| VEYA
! DEĞİL
Kaydırma
Operatör Açıklama
>> Sağa
<< Sola
7. Karşılaştırma deyimleri
if-else if-else
Ornek7
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 ornek7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
switch-case
Ornek8
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 ornek8
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
8. Döngü komutları
for
Ornek9
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 ornek9
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
while
Ornek10
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 ornek10
{ public partial class Form1 : Form
{ public Form1()
{ InitializeComponent(); }