Merve Yıldız

C# 4

Nisan22

Bu haftaki dersimizde nesneye yönelik programlamaya geciyoruz.Program içinde ayrı class lar acıyoruz ve bu classlar yolu ile programımızı calıştırıyoruz..

Ana classımız:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ders4
{
class Program
{

static void Main(string[] args) // Ana class içinde yapıılcak işlemleri cagırıyoruz
{
while(true){
rehber.nesneekle(); // rehberimize yeni nesne ekleme
rehber.nesneleriyazdir(); // rehberimizdeki nesneleri ekrana yazdırma
rehber.settelfon(5);
}

}
}
}

Diger classımız:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

// pencere classımızda telefon rehberi haricinde örnek yapıyoruz.yeni nesneler oluşturup,toplam nesne sayısını ekrana yazdırıyoruz.Ayrıca verdigimiz kordinatların dönüşümünü yaptırıp ekrana yazdırıyoruz.

namespace ders4
{
class pencere
{
private int koordinatx;
private int koordinaty;
public static int nesnesayisi = 0;

public static void nesnesayisiniyazdir(){
Console.WriteLine(nesnesayisi)
public pencere(){
Console.WriteLine(“yeni nesne oluştu”);
nesnesayisi++;

}

public pencere(int koordinatx,int koordinaty){
this.koordinatx = koordinatx;
this.koordinaty = koordinaty;
nesnesayisi++;

}

public int Koordinatx{
get{return koordinatx;}

set{
if (value >= 0)
{

koordinatx = value;
}

}
}

public int Koordinaty
{
get { return koordinaty; }
set
{
if (value >= 0)
{
koordinaty = value;
}

}
}
public void ekranayaz()
{
Console.WriteLine(this.koordinatx + ” ” + this.koordinaty);
}

public void ekranayaz(int x){
for (int i = 0; i < x;i++ )
{
Console.WriteLine(this.koordinatx + ” ” + this.koordinaty);
}
}

}
}

Telefon rehberi classımız:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ders4
{
class rehber
{
private int id;
public int Id
{
get { return id; }
}

private string isim;
public string Isim
{
get { return isim; } // string halinde girilen ismi döndürür
}

private string telefon;
public string Telefon
{
get { return telefon; } // string halinde girilen telefon numarasını döndürür
set {

telefon = value;

}
}

private rehber next;

private static int nesnesayisi =0;

private rehber(string isim , string telefon){
nesnesayisi++;
id = nesnesayisi;
next = null;

this.isim = isim;
this.telefon = telefon;

}

private rehber()
{
nesnesayisi++;
id = nesnesayisi;
next = null;
Console.WriteLine(“İsim giriniz.”);
this.isim = Console.ReadLine();
Console.WriteLine(“Telefon Giriniz”);
this.telefon = Console.ReadLine();

}

public static rehber ilknesne = null;

public static void nesneekle(){
rehber temp;
if (ilknesne == null)
{
ilknesne = new rehber();
}else{
temp = ilknesne;
while(temp.next != null){
temp = temp.next;
}
temp.next = new rehber();
}
}

public static void nesneleriyazdir(){
rehber temp = ilknesne;

while(temp != null){
Console.WriteLine(temp.id + ” ” + temp.isim + ” ” + temp.telefon);
temp = temp.next;
}
}

public static void settelfon(int id){
rehber temp = ilknesne;

while (temp != null)
{
if (temp.id == id)
{
Console.WriteLine(“Telefon giriniz”);
temp.telefon = Console.ReadLine();
}
temp = temp.next;
}
}
}
}

posted under Kategorilenmemiş

Comments are closed.