7. Build ve
Kod Yaz Check in
Test
Fix
edilebilir Sebebini Build evet
Evet mi?? araştır hayır başarılı mı?
Hayır
Tüm ekip
bekler
Gated Automate
Kod Yaz
check-in d build
Check-in’i
Test için kaydet
Build hayır
hazır (commit) evet başarılı mı?
11. public class Zaman {
public double Saniye;
public double Saat;
}
public class Zaman {
public double Saniye;
public double GetSaat(){
return saniye/3600;
}
public void SetSaat(double value){
saniye = value * 3600;
}
}
...
Zaman zaman = new Zaman();
zaman.SetSaat(3);
12. public class Zaman {
public double Saniye;
public double Saat;
}
public class Zaman {
public double Saniye;
public double Saat{
get{ return saniye/3600;}
set{ saniye = value * 3600;}
}
}
...
Zaman zaman = new Zaman();
zaman.Saat = 3;
13. public class Zaman {
public double Saniye;
public double Saat;
}
public class Zaman {
public double Saniye;
public double Saat{
get{ return saniye/3600;}
}
}
...
Zaman zaman = new Zaman();
zaman.Saat = 3;
14. public class Zaman {
public double Saniye;
public double Saat;
}
public class Zaman {
public double Saniye;
private double _saat;
public double Saat {
get { return _saat; }
set { _saat = value; };
}
}
15. public class Zaman {
public double Saniye;
private double _saat;
public double Saat {
get { return _saat; }
set { _saat = value; };
}
}
public class Zaman {
public double Saniye;
public double Saat { get; set; }
}
18. public interface IInsan {
string Adi { get; set; }
int Yasi { get; set; }
void Konus();
}
public class Erkek : IInsan {
private string _adi
public string Adi { get { return _adi; } set { _adi = value; } }
private int _yasi
public int Yasi { get { return _yasi; } set { _yas = value; } }
public void Konus(){
//...
}
}
19. IInsan insan = new Erkek();
Console.WriteLine(insan.Adi);
insan = new Kadin();
Console.WriteLine(insan.Adi);
public class IOgrenci : IInsan {
//...
}
20. public abstract class Sekil {
public abstract void Ciz(int x, int y);
}
public class Kare: Sekil {
public override void Ciz(int x, int y){
//kare çizim kodu
}
}
Sekil sekil = new Kare();
Console.WriteLine(sekil.Adi);
Sekil.Ciz(0, 0);
21. public abstract class Sekil {
private string _adi;
public string Adi {
get { return _adi; }
}
public abstract void Ciz(int x, int y);
}
public class Kare: Sekil {
public override void Ciz(int x, int y){
//kare çizim kodu
}
}
22. delegate tanımı parametreler
public delegate void Uyari(string mesaj);
.
.
atama
.
Uyari uyari = delegate(string mesaj) {
MessageBox.Show(mesaj);
};
uyari("Hatalı değer girildi");
.
. kullanımı
uyari("Lütfen yeniden deneyiniz");
uyari = delegate{
MessageBox.Show("Hata oluştu"); Alternatif
}; tanımlama
uyari("kullanımayan parametre");
23. delegate tanımı event tanımı
public delegate void SurecDegistiIsleyici(int tamamlanmaOrani);
public event SurecDegistiIsleyici SurecDegisti;
islem.SurecDegisti += new SurecDegistiIsleyici(islem_SurecDegisti);
void islem_SurecDegisti(int tamamlanmaOrani) { Olay bildirimine
.
.
kayıt
}
Olay gerçekleştiğinde
işletilecek süreç
24. Olay bildirimine
kayıt
islem.SurecDegisti += islem_SurecDegisti;
.
.
islem.SurecDegisti -= islem_SurecDegisti;
Olay bildirimine
kaydı silme
25. Özel temsilci
(delegate)
private SurecDegistiIsleyici _surecDegistiIsleyici;
Olay bildirimine
public event SurecDegistiIsleyici SurecDegisti { kayıt
add { _surecDegistiIsleyici += value; }
remove { _surecDegistiIsleyici -= value; }
}
Olay bildirimine
kaydı silme
26. Olay bildirimine kayıt
olunduğuna emin olun
protected virtual void OnSurecDegistiIsleyici(int tamamlanmaOrani) {
if (SurecDegistiIsleyici != null) {
SurecDegistiIsleyici(tamamlanmaOrani);
}
}
Olay bildirimini tetikleyin
29. public class Ogrenci {
public string Adi;
public string Bolum;
}
List<Ogrenci> ogrenciler = new List<Ogrenci> {
new Ogrenci{ Adi = "Duru", Bolum = "Bil. Müh." },
new Ogrenci{ Adi = "Fatih", Bolum = "Bil. Müh." },
new Ogrenci{ Adi = "Melis", Bolum = "Deri Müh." }
};
Bilgisayar mühendisi olan öğrencilerin listesi;
List<Ogrenci> bilMuhOgrencileri = new List<Ogrenci>();
foreach (Ogrenci ogrenci in ogrenciler) {
if (ogrenci.Bolum == "Bil. Müh.") {
bilMuhOgrencileri.Add(ogrenci);
}
}
30. public class Ogrenci {
public string Adi;
public string Bolum;
}
List<Ogrenci> ogrenciler = new List<Ogrenci> {
new Ogrenci{ Adi = "Duru", Bolum = "Bil. Müh." },
new Ogrenci{ Adi = "Fatih", Bolum = "Bil. Müh." },
new Ogrenci{ Adi = "Melis", Bolum = "Deri Müh." }
};
List<Ogrenci> bilMuhOgrencileri = ogrenciler.FindAll(
delegate(Ogrenci ogrenci) {
return ogrenci.Bolum == "Bil. Müh.";
}
);
31. public class Ogrenci {
public string Adi;
public string Bolum;
}
List<Ogrenci> ogrenciler = new List<Ogrenci> {
new Ogrenci{ Adi = "Duru", Bolum = "Bil. Müh." },
new Ogrenci{ Adi = "Fatih", Bolum = "Bil. Müh." },
new Ogrenci{ Adi = "Melis", Bolum = "Deri Müh." }
};
List<Ogrenci> bilMuhOgrencileri = ogrenciler.FindAll(ogrenci =>
ogrenci.Bolum == "Bil. Müh.");
List<Ogrenci> bilMuhOgrencileri = ogrenciler.FindAll((Ogrenci
ogrenci) => ogrenci.Bolum == "Bil. Müh.");
32. Lambda ifadeler
temsilcilere atanabilir
public delegate void Uyari(string mesaj);
.
.
.
Uyari uyari = mesaj => MessageBox.Show(mesaj);
uyari("Hatalı değer girildi");
.
.
uyari("Lütfen yeniden deneyiniz");
33. Lambda ifadeler yerel değişkenleri ve tanımlandıkları metod’a ait parametreleri
(dış değişkenleri) kullanabilirler;
public delegate void Uyari(string mesaj);
.
.
.
string varsayilanMesaj = "Hata Oluştu";
Uyari uyari = mesaj => MessageBox.Show(mesaj ?? varsayilanMesaj);
uyari("Hatalı değer girildi");
.
.
uyari(null);
34. Lambda ifadelerince kullanılan dış değişkenlerin değerleri lambda ifade
çağırıldığında hesaplanır;
int carpan = 3;
Func<int, int> carpim = x => x * carpan;
int sonuc1 = carpim(2); // sonuc1 = 6
carpan = 10;
int sonuc2 = carpim(2); // sonuc2 = 20
• Bir dış değişkenin değeri lambda ifade içerisinde değiştirilebilir
• Lambda ifade içerisinde tanımlanan değişkenler her çağırım için tekildirler
35.
36.
37. Genişletme metodunun string
türü için olduğunu belirtir
public static class StringEx {
public static bool BosYadaBoslukMu(this string stringIfade) {
return string.IsNullOrEmpty(stringIfade) ||
stringIfade.Trim() == string.Empty;
}
}
Örnek kullanım;
string ornek = "Örnek";
Console.Write(ornek.BosYadaBoslukMu());
Derleyici taradından oluşturulan kod;
string ornek = "Örnek";
Console.Write(StringEx.BosYadaBoslukMu(ornek));
38. public static IEnumerable<int> To(this int ilk, int son)
{
for (var l = ilk; l <= son; l++)
{
yield return l;
}
}
foreach (int i in 5.To(15))
{
j = i*i;
}
40. var ogrenci = new {Adi = "Fatih", Bolum = "Bil. Müh." }
Derleyici tarafından üretilen kod;
internal class OtomatikUretilmisTurAdi
{
private string adi; //gercekte farkli bir ad verilebilir
private int bolum; //gercekte farkli bir ad verilebilir
public OtomatikUretilmisTurAdi (string adi, string bolum) {
this.adi = adi;
this.bolum = bolum;
}
public string Adi { get { return adi; } }
public string Bolum { get { return bolum; } }
}
var ogrenci = new OtomatikUretilmisTurAdi("Fatih", "Bil. Müh.");
41. var ogrenci = new {Adi = "Fatih", Bolum = "Bil. Müh." }
string Adi = "Fatih";
string Bolum = "Bil. Müh.";
var ogrenci = new {Adi, Bolum };
string Adi = "Fatih";
string Bolum = "Bil. Müh.";
var ogrenci = new {Adi = Adi, Bolum = Bolum };
42. var ogrenci1 = new {Adi = "Fatih", Bolum = "Bil. Müh." };
var ogrenci2 = new {Adi = "Melis", Bolum = "Deri Müh." };
bool sonuc = ogrenci1.GetType() == ogrenci2.GetType(); //true
43. object nesne = 1;
if (nesne.GetType() == typeof(int)){
Console.WriteLine("Tabiki türü int");
}
44. object nesne = 1;
if (nesne.GetType() == typeof(int)){
Console.WriteLine("Tabiki türü int");
}
nesne = nesne + 1;
Yukarıdaki kodun derlenebilmesi için int türüne dönüşüm gerekli;
object nesne = 1;
if (nesne.GetType() == typeof(int)){
Console.WriteLine("Tabiki türü int");
}
nesne = (int)nesne + 1;
45. Aşağıdaki kod derleme zamanı hata vermese de çalışma zamanı hata oluşturur;
object nesne = 1;
if (nesne.GetType() == typeof(int)){
Console.WriteLine("Tabiki türü int");
}
nesne = (string)nesne + 1;
46. dynamic nesne = 1;
if (nesne.GetType() == typeof(int)){
Console.WriteLine("Tabiki türü int");
}
dynamic nesne = 1;
if (nesne.GetType() == typeof(int)){
Console.WriteLine("Tabiki türü int");
}
nesne = nesne + 1
47. Dinamik kullanılırken derleyici desteği olmayacağı için geliştirme zamanı kod
daha fazla hataya açıktır. Örneğin aşağıdaki kod derleme zamanı hata vermezken
çalışma zamanında hataya neden olacaktır;
dynamic nesne = 1;
if (nesne.GetType() == typeof(int)){
Console.WriteLine("Tabiki türü int");
}
Nesne.VarolmayanBirMetod();
48. Bir önceki örneğin derlenmesi sonucu oluşan C# kodu;
internal class Program {
private static void Main(string[] args) {
object nesne = 1;
if (<ma IN>o__SiteContainer0.<>p__Site1 == null) {
<ma IN>o__SiteContainer0.<>p__Site1 = CallSite<func><calls ITE, object, bool>>.Create(
Binder.UnaryOperation(CSharpBinderFlags.None,
ExpressionType.IsTrue,
typeof(Program),
new CSharpArgumentInfo[] {
CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null)
}));
}
if (<ma IN>o__SiteContainer0.<>p__Site2 == null) {
<ma IN>o__SiteContainer0.<>p__Site2 = CallSite<func><calls ITE, object, Type, object>>.Create(
Binder.BinaryOperation(CSharpBinderFlags.None,
ExpressionType.Equal,
typeof(Program),
new CSharpArgumentInfo[] {
CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null),
CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null)
}));
}
if (<ma IN>o__SiteContainer0.<>p__Site3 == null) {
<ma IN>o__SiteContainer0.<>p__Site3 = CallSite<func><calls ITE, object, object>>.Create(
Binder.InvokeMember(CSharpBinderFlags.None,
"GetType",
null,
typeof(Program),
new CSharpArgumentInfo[] {
CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null)
}));
}
if (<ma IN>o__SiteContainer0.<>p__Site1.Target.Invoke(<ma IN>o__SiteContainer0.<>p__Site1,
<ma IN>o__SiteContainer0.<>p__Site2.Target.Invoke(<ma IN>o__SiteContainer0.<>p__Site2,
<ma IN>o__SiteContainer0.<>p__Site3.Target.Invoke(
<ma IN>o__SiteContainer0.<>p__Site3, nesne),
typeof(int)))) {
Console.WriteLine("Tabi ki tx00fcrx00fc int");
}
else {
Console.WriteLine("Tx00fcm makale hatalıymış :P");
}
if (<ma IN>o__SiteContainer0.<>p__Site4 == null) {
<ma IN>o__SiteContainer0.<>p__Site4 = CallSite<func><calls ITE, object, object int,>>.Create(
Binder.BinaryOperation(CSharpBinderFlags.None,
ExpressionType.Add, typeof(Program),
new CSharpArgumentInfo[] {
CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null),
CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.Constant | CSharpArgumentInfoFlags.UseCompileTimeType, null)
}));
}
nesne = <ma IN>o__SiteContainer0.<>p__Site4.Target.Invoke(<ma IN>o__SiteContainer0.<>p__Site4, nesne, 1);
}
[CompilerGenerated]
private static class <ma IN>o__SiteContainer0 {
public static CallSite<func><calls ITE, object, bool>> <>p__Site1;
public static CallSite<func><calls ITE, object, Type, object>> <>p__Site2;
public static CallSite<func><calls ITE, object, object>> <>p__Site3;
public static CallSite<func><calls ITE, object, object int,>> <>p__Site4;
}
}
49.
50.
51.
52. Sadece sınıflar için Aynı sınıf üzerinde birden
kullanılabilir fazla kullanılamaz
[AttributeUsage(
AttributeTargets.Class,
AllowMultiple = false,
Inherited = false)]
public class OrnekAttribute : Attribute { }
Alt sınıflarda tanımlı değil Bir öznitelik
tanımlandığını belirtir
53. public class Ogrenci {
public string Adi;
public string Bolum;
}
FieldInfo[] ogrencialanlari = typeof(Ogrenci).GetFields(
BindingFlags.Public |
BindingFlags.Instance);
foreach (var ogrenciAlani in ogrencialanlari) {
Console.WriteLine("Alan :" + ogrenciAlani.Name);
}
Çıktı;
Alan : Adi
Alan : Bolum
55. <?xml version="1.0" encoding="utf-8"?>
<Ogrenci xmlns="http://www.enterprisecoding.com"
Adi="Fatih"
Bolum="Bil. Müh." />
Tür’ün tanımlı olacağı xml
Xml tür adı
isimuzayı
[XmlType(Namespace="http://www.enterprisecoding.com",TypeName="Ogrenci")]
public class Ogrenci {
[XmlAttribute]
public string Adi; Veri elemanının xml içerisinde
ne şekilde tutulacağını belirtir
[XmlAttribute]
public string Bolum;
}
56. Xml dokümanı giriş elemanı
[XmlRoot(Namespace="http://www.enterprisecoding.com",ElementName="Ogrenci
Listesi")]
public class OgrenciListesi { Xml içerisinde oluşturulacak
[XmlArray(ElementName="Ogrenciler")]
array tanımlaması
[XmlArrayItem(ElementName="Ogrenci")]
public Ogrenci[] Ogrenciler;
}
Xml içerisinde oluşturulacak array
elemanlarının tanımlaması
57. Serileştirilecek tür
XmlSerializer serializer = new XmlSerializer(typeof(OgrenciListesi));
OgrenciListesi ogrenciListesi = new OgrenciListesi {
Ogrenciler = new[] {
new Ogrenci{ Adi = "Ali", Bolum = "Bil. Müh." },
new Ogrenci{ Adi = "Fatih", Bolum = "Bil. Müh." },
new Ogrenci{ Adi = "Melis", Bolum = "Deri Müh." }
}
};
using (StreamWriter dosya = File.CreateText("ogrenciListesi.xml")) {
serializer.Serialize(dosya, ogrenciListesi);
}
Serileştirmenin yapılacağı
Serileştirilecek nesne
stream
60. XmlSerializer serializer = new XmlSerializer(typeof(OgrenciListesi));
using (StreamReader dosya = File.OpenText("ogrenciListesi.xml")) {
var ogrenciListesi=(OgrenciListesi)serializer.Deserialize(dosya);
.
.
.
}
61. public class Ogrenci {
public string Adi;
public string Bolum;
}
List<Ogrenci> ogrenciler = new List<Ogrenci> {
new Ogrenci{ Adi = "Ali", Bolum = "Bil. Müh." },
new Ogrenci{ Adi = "Fatih", Bolum = "Bil. Müh." },
new Ogrenci{ Adi = "Melis", Bolum = "Deri Müh." }
};
var bilMuhOgrencileri = ogrenciler.Where(ogrenci => ogrenci.Bolum ==
"Bil. Müh.");
62. Aynı sorgunun farklı bir şekilde ifadesi;
var bilMuhOgrencileri = from ogrenci in ogrenciler
where ogrenci.Bolum == "Bil. Müh."
select ogrenci;
Sadece öğrencilerin adını sorgulamak için;
var bilMuhOgrencileri = from ogrenci in ogrenciler
where ogrenci.Bolum == "Bil. Müh."
select ogrenci.Adi;
63. Aynı sorgu, isimler sıralı şekilde;
var bilMuhOgrencileri = from ogrenci in ogrenciler
where ogrenci.Bolum == "Bil. Müh."
orderby ogrenci.Adi ascending
select ogrenci;
Sorgu Sözdizimi
(Query Syntax/Query Expression Syntax)
Başka bir ifade ile;
var bilMuhOgrencileri = ogrenciler
.Where(ogrenci => ogrenci.Bolum == "Bil. Müh.")
.OrderBy(ogrenci => ogrenci.Adi)
.Select(ogrenci => ogrenci);
Akıcı Sözdizimi
(Fluent Syntax)
64. Bir önceki örnekteki akıcı sözdizimini incelersek;
var bilMuhOgrencileri = ogrenciler
.Where(ogrenci => ogrenci.Bolum == "Bil. Müh.")
.OrderBy(ogrenci => ogrenci.Adi)
.Select(ogrenci => ogrenci);
var filtrelenmis = ogrenciler.Where(ogrenci=>ogrenci.Bolum=="Bil. Müh.");
var siralanmıs = filtrelenmis.OrderBy(ogrenci => ogrenci.Adi);
var sorgu = siralanmıs.Select(ogrenci => ogrenci);
73. public static IEnumerable<int> To(this int ilk, int son)
{
for (var l = ilk; l <= son; l++)
{
yield return l;
}
}
foreach (int i in 5.To(15))
{
j = i*i;
}
82. var veri = VeriyiIndir(...);
VeriyiIsle(veri);
VeriyiIndirAsync(... , veri => {
VeriyiIsle(veri);
});
83.
84. public TResult VeriyiIndir(TParam parametre);
…
public IAsyncResult BeginVeriyiIndir
(TParam parametre, AsyncCallback geriCagri, object durum);
public TResult EndVeriyiIndir (IAsyncResult asenkronSonuc);
85. public TResult VeriyiIndir(TParam parametre);
…
public void VeriyiIndirAsync(TParam parametre);
public event VeriIndirTamamlandiEventHandler
VeriIndirTamamlandi;
public delegate void VeriIndirTamamlandiEventHandler(
object sender, VeriIndirTamamlandiEventArgs eventArgs);
public class VeriIndirTamamlandiEventArgs :
AsyncCompletedEventArgs
{
public TResult Sonuc { get; }
}
114. Sınıf
Meta-programlama Oku-Çalıştır-Yaz
public Foo Döngüsü
Dil Nesne Modeli alan
private X
string
.NET
Kaynak Kodu
Source code Assembly
Source code
Source code Compiler
Derleyici Source code