/
05.09.2018.cs
248 lines (237 loc) · 5.26 KB
/
05.09.2018.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace derstekikodlaricalistirma
{
// Yapıcı metotlar ( constructor metotlar ) sınıftan nesne türettiğin anda
// yapılmasını istediğin işleri yaptırmak için kullanılan metottur.
// geriye değer üretmez ve voidle belirtilmez
// yapıcı metotlar sınıfın adıyla aynıdır.
class ogrenci
{
public ogrenci()
{
ono = 5; // nesne türetildiği anda öğrenci numarasına 5 değeri ata
Console.WriteLine("yapıcı çalıştı");
}
public string oad;
public int ono;
}
class Program
{
static void Main(string[] args)
{
ogrenci o1 = new ogrenci();
Console.WriteLine(o1.ono);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace derstekikodlaricalistirma
{
class mat
{
public mat (int a,int b)
{
Console.WriteLine(a+b);
}
}
class Program
{
static void Main(string[] args)
{
mat m = new mat(3, 5);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace derstekikodlaricalistirma
{
class mat
{
public mat (int a,int b)
{
Console.WriteLine(a+b);
}
public mat()
{
Console.WriteLine("parametresiz yapıcı");
}
}
class Program
{
static void Main(string[] args)
{
mat m1 = new mat();
mat m = new mat(3, 5);
mat m2 = new mat();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace derstekikodlaricalistirma
{
// bu olay sadece yapıcı metotlarda geçerli !!
class mat
{
public mat(int a,int b,int c)
{
Console.WriteLine(a+b+c);
}
public mat (int d,int e):this(d,e,0) // sınıfa ait 3 yapıcılı metota gönder
{
}
public mat(int f):this(f,0)
{
}
}
class Program
{
static void Main(string[] args)
{
mat m1 = new mat(5);
mat m2 = new mat(5, 7);
mat m3 = new mat(3, 5, 7);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace derstekikodlaricalistirma
{
class ornek
{
ornek()
{
Console.WriteLine("yapıcı");
}
public ornek(int a)
{
Console.WriteLine("parametreli yapıcı");
new ornek();
}
/* Başka metotlar olabilir
ve ornek() burda çağrılabilirdi*/
}
class Program
{
static void Main(string[] args)
{
ornek o = new ornek(5);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace derstekikodlaricalistirma
{
class test
{
public test()
{
Console.WriteLine("yapıcı"); // normaller her nesne türettiğinde çalışıyor
}
static test() // static metotlar public olmak zorundadır bu yüzden erişim belirteci belirtilmez
{
Console.WriteLine("static yapıcı"); // bir kez çalışır nesneyi türettiğin anda
}
}
class Program
{
static void Main(string[] args)
{
test t1 = new test();
test t2 = new test();
test t3 = new test();
test t4 = new test();
test t5 = new test();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace derstekikodlaricalistirma
{
class test
{
public static int a = 5;
public test()
{
Console.WriteLine("s olmayan yapıcı");
}
static test()
{
Console.WriteLine("statik yapıcı");
}
public static void yaz()
{
Console.WriteLine("huhu");
}
}
class Program
{
static void Main(string[] args)
{
test.yaz();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace derstekikodlaricalistirma
{
// yıkıcı örnek
// yıkıcı metotun erişim belirteci kullanılmaz
// void felan belirtilmez
// yıkıcı metotun adı sınıfın adıyla aynıdır
// parametre almaz
// tilda işareti koyulur ~
class sinif_ornek
{
public sinif_ornek()
{
Console.WriteLine("yapıcı");
}
~sinif_ornek()
{
Console.WriteLine("yıkıcı çalıştı");
}
}
class Program
{
static void Main(string[] args)
{
if(1==1)
{
sinif_ornek s1 = new sinif_ornek();
}
int a = Convert.ToInt32(Console.ReadLine());
}
}
}