Tam Sayı Değişken Tipleri
-------------------------
Type Size Range (aralık)
sbyte 8 -128 to 127
byte 87 0 to 255
short 16 -32768 to 32767
ushort 16 0 to 65535
int 32 -2147483648 to 2147483647
uint 32 0 to 4294967295
long 64 -9223372036854775808 to 9223372036854775807
ulong 64 0 to 18446744073709551615
char 16 0 to 65535
Ondalıklı Değişken Tipleri
--------------------------
Type Size Range
float 32 7 digits 1.5 x 10-45 to 3.4 x 1038
Double 64 15-16 digits 5.0 x 10-324 to 1.7 x 10308
Decimal 128 28-29 decimal places 1.0 x 10-28 to 7.9 x 1028
Diğer Değişken Tipleri
----------------------
string karaktersel ifadeler için kullanılır
bool mantıksal değişken. (true ve false değerlerini alır)
30 Eylül 2010 Perşembe
C# da Parse Methodu ile Tip Dönüşümleri
Açıklama:
---------
Parse, String tipteki verilerin sayısal tiplere dönüşümünü sağlayan methoddur.
Kullanımı:
----------
tip_adı.Parse(string veri);
Örnek Kodlama:
--------------
using System;
using System.Collections.Generic;
using System.Text;
namespace console_008
{
class Program
{
static void Main(string[] args)
{
int a, b, t;
Console.Write("1.Sayıyı Giriniz :");
a = int.Parse(Console.ReadLine());
Console.Write("2.Sayıyı Giriniz :");
b = int.Parse(Console.ReadLine());
t = a + b;
Console.WriteLine("Sayıların Toplamı :"+t);
Console.ReadKey();
}
}
}
---------
Parse, String tipteki verilerin sayısal tiplere dönüşümünü sağlayan methoddur.
Kullanımı:
----------
tip_adı.Parse(string veri);
Örnek Kodlama:
--------------
using System;
using System.Collections.Generic;
using System.Text;
namespace console_008
{
class Program
{
static void Main(string[] args)
{
int a, b, t;
Console.Write("1.Sayıyı Giriniz :");
a = int.Parse(Console.ReadLine());
Console.Write("2.Sayıyı Giriniz :");
b = int.Parse(Console.ReadLine());
t = a + b;
Console.WriteLine("Sayıların Toplamı :"+t);
Console.ReadKey();
}
}
}
C# Console da ReadLine( ) komutu
Açıklama:
Console ortamında klavyeden bilgi okutmak amacıyla kullanılan bir komuttur. Okutulan bilgiler her zaman string tipindedir. Dolayısıyla sayı ya da başka tipte kullanım yapılmak istendiğinde tip dönüşümü yapılması gerekir. Tip dönüşümleri başka derslerde açıklanacaktır.
Örnek Kodlama :
---------------
using System;
using System.Collections.Generic;
using System.Text;
namespace console_007
{
class Program
{
static void Main(string[] args)
{
string s;
s = Console.ReadLine();
Console.WriteLine("Girdiğiniz Metin : "+s);
Console.ReadKey();
}
}
}
Console ortamında klavyeden bilgi okutmak amacıyla kullanılan bir komuttur. Okutulan bilgiler her zaman string tipindedir. Dolayısıyla sayı ya da başka tipte kullanım yapılmak istendiğinde tip dönüşümü yapılması gerekir. Tip dönüşümleri başka derslerde açıklanacaktır.
Örnek Kodlama :
---------------
using System;
using System.Collections.Generic;
using System.Text;
namespace console_007
{
class Program
{
static void Main(string[] args)
{
string s;
s = Console.ReadLine();
Console.WriteLine("Girdiğiniz Metin : "+s);
Console.ReadKey();
}
}
}
14 Mayıs 2010 Cuma
C# da Text Dosyadan Kayıt Silme İşlemi
string ad, soyad, tel, yol, yol2;
FileStream dosya, dosya2;
private void Form1_Load(object sender, EventArgs e)
{
yol = Application.StartupPath + "\\telefon.txt";
yol2 = Application.StartupPath + "\\gecici.txt";
}
private void button4_Click(object sender, EventArgs e)
{
dosya = new FileStream(yol, FileMode.OpenOrCreate, FileAccess.Read);
StreamReader okuma;
okuma = new StreamReader(dosya);
dosya2 = new FileStream(yol2, FileMode.Create, FileAccess.Write);
StreamWriter yazma;
yazma = new StreamWriter(dosya2);
do
{
ad = okuma.ReadLine();
soyad = okuma.ReadLine();
tel = okuma.ReadLine();
if (textBox1.Text != ad)
{
yazma.WriteLine(ad);
yazma.WriteLine(soyad);
yazma.WriteLine(tel);
}
}
while (ad != null);
okuma.Close();
yazma.Close();
File.Delete(yol);
File.Move(yol2, yol);
}
FileStream dosya, dosya2;
private void Form1_Load(object sender, EventArgs e)
{
yol = Application.StartupPath + "\\telefon.txt";
yol2 = Application.StartupPath + "\\gecici.txt";
}
private void button4_Click(object sender, EventArgs e)
{
dosya = new FileStream(yol, FileMode.OpenOrCreate, FileAccess.Read);
StreamReader okuma;
okuma = new StreamReader(dosya);
dosya2 = new FileStream(yol2, FileMode.Create, FileAccess.Write);
StreamWriter yazma;
yazma = new StreamWriter(dosya2);
do
{
ad = okuma.ReadLine();
soyad = okuma.ReadLine();
tel = okuma.ReadLine();
if (textBox1.Text != ad)
{
yazma.WriteLine(ad);
yazma.WriteLine(soyad);
yazma.WriteLine(tel);
}
}
while (ad != null);
okuma.Close();
yazma.Close();
File.Delete(yol);
File.Move(yol2, yol);
}
C# da Text Dosyada Kayıt Arama İşlemi
string ad, soyad, tel, yol, yol2;
FileStream dosya, dosya2;
private void Form1_Load(object sender, EventArgs e)
{
yol = Application.StartupPath + "\\telefon.txt";
yol2 = Application.StartupPath + "\\gecici.txt";
}
private void button3_Click(object sender, EventArgs e)
{
Boolean bul;
bul = false;
dosya = new FileStream(yol, FileMode.OpenOrCreate, FileAccess.Read);
StreamReader okuma;
okuma = new StreamReader(dosya);
do
{
ad = okuma.ReadLine();
soyad = okuma.ReadLine();
tel = okuma.ReadLine();
if (textBox1.Text == ad)
{
bul = true;
textBox2.Text = soyad;
textBox3.Text = tel;
}
}
while (ad != null);
if (bul == false) MessageBox.Show("Aradığınız Kayıt Bulunamadı");
okuma.Close();
}
FileStream dosya, dosya2;
private void Form1_Load(object sender, EventArgs e)
{
yol = Application.StartupPath + "\\telefon.txt";
yol2 = Application.StartupPath + "\\gecici.txt";
}
private void button3_Click(object sender, EventArgs e)
{
Boolean bul;
bul = false;
dosya = new FileStream(yol, FileMode.OpenOrCreate, FileAccess.Read);
StreamReader okuma;
okuma = new StreamReader(dosya);
do
{
ad = okuma.ReadLine();
soyad = okuma.ReadLine();
tel = okuma.ReadLine();
if (textBox1.Text == ad)
{
bul = true;
textBox2.Text = soyad;
textBox3.Text = tel;
}
}
while (ad != null);
if (bul == false) MessageBox.Show("Aradığınız Kayıt Bulunamadı");
okuma.Close();
}
C# da Text Dosyadan Okuma İşlemi (Listeleme)
string ad, soyad, tel, yol, yol2;
FileStream dosya, dosya2;
private void Form1_Load(object sender, EventArgs e)
{
yol = Application.StartupPath + "\\telefon.txt";
yol2 = Application.StartupPath + "\\gecici.txt";
}
private void button2_Click(object sender, EventArgs e)
{
dosya = new FileStream(yol, FileMode.OpenOrCreate, FileAccess.Read);
StreamReader okuma;
okuma = new StreamReader(dosya);
listBox1.Items.Clear();
listBox2.Items.Clear();
listBox3.Items.Clear();
do
{
ad = okuma.ReadLine();
soyad = okuma.ReadLine();
tel = okuma.ReadLine();
if (ad != null)
{
listBox1.Items.Add(ad);
listBox2.Items.Add(soyad);
listBox3.Items.Add(tel);
}
}
while (ad != null); //Şart sağlandığı sürece döngü çalışır.
okuma.Close();
}
FileStream dosya, dosya2;
private void Form1_Load(object sender, EventArgs e)
{
yol = Application.StartupPath + "\\telefon.txt";
yol2 = Application.StartupPath + "\\gecici.txt";
}
private void button2_Click(object sender, EventArgs e)
{
dosya = new FileStream(yol, FileMode.OpenOrCreate, FileAccess.Read);
StreamReader okuma;
okuma = new StreamReader(dosya);
listBox1.Items.Clear();
listBox2.Items.Clear();
listBox3.Items.Clear();
do
{
ad = okuma.ReadLine();
soyad = okuma.ReadLine();
tel = okuma.ReadLine();
if (ad != null)
{
listBox1.Items.Add(ad);
listBox2.Items.Add(soyad);
listBox3.Items.Add(tel);
}
}
while (ad != null); //Şart sağlandığı sürece döngü çalışır.
okuma.Close();
}
C# da Text Dosyaya Kayıt İşlemi
string ad, soyad, tel, yol, yol2;
FileStream dosya, dosya2;
private void Form1_Load(object sender, EventArgs e)
{
yol = Application.StartupPath + "\\telefon.txt";
yol2 = Application.StartupPath + "\\gecici.txt";
}
//Kaydet Butonu
private void button1_Click(object sender, EventArgs e)
{
ad = textBox1.Text;
soyad = textBox2.Text;
tel = textBox3.Text;
dosya = new FileStream(yol, FileMode.Append, FileAccess.Write);
StreamWriter yazma;
yazma = new StreamWriter(dosya);
yazma.WriteLine(ad);
yazma.WriteLine(soyad);
yazma.WriteLine(tel);
yazma.Close();
}
FileStream dosya, dosya2;
private void Form1_Load(object sender, EventArgs e)
{
yol = Application.StartupPath + "\\telefon.txt";
yol2 = Application.StartupPath + "\\gecici.txt";
}
//Kaydet Butonu
private void button1_Click(object sender, EventArgs e)
{
ad = textBox1.Text;
soyad = textBox2.Text;
tel = textBox3.Text;
dosya = new FileStream(yol, FileMode.Append, FileAccess.Write);
StreamWriter yazma;
yazma = new StreamWriter(dosya);
yazma.WriteLine(ad);
yazma.WriteLine(soyad);
yazma.WriteLine(tel);
yazma.Close();
}
Kaydol:
Kayıtlar (Atom)