Foreword |
|
xxiii | |
|
Foreword |
|
xxv | |
|
About the Author |
|
xxvii | |
About the Technical Reviewers |
|
xxix | |
Acknowledgements |
|
xxxi | |
Preface |
|
xxxiii | |
Guidelines for Using the Book |
|
xxxvii | |
|
Part I Enter into the World of OOP |
|
|
1 | (242) |
|
Chapter 1 Object-Oriented Programming Concepts |
|
|
3 | (8) |
|
|
5 | (1) |
|
|
6 | (1) |
|
|
6 | (1) |
|
|
7 | (1) |
|
|
7 | (2) |
|
|
9 | (2) |
|
Chapter 2 The Building Blocks: Class and Objects |
|
|
11 | (30) |
|
|
11 | (1) |
|
|
11 | (4) |
|
|
15 | (1) |
|
|
16 | (3) |
|
|
17 | (1) |
|
|
17 | (2) |
|
|
19 | (8) |
|
|
20 | (1) |
|
|
20 | (1) |
|
|
21 | (2) |
|
|
23 | (1) |
|
|
23 | (1) |
|
|
24 | (3) |
|
|
27 | (3) |
|
|
28 | (1) |
|
|
28 | (2) |
|
|
30 | (1) |
|
|
31 | (1) |
|
|
31 | (1) |
|
|
31 | (2) |
|
|
32 | (1) |
|
|
33 | (1) |
|
|
33 | (2) |
|
|
34 | (1) |
|
|
35 | (1) |
|
|
35 | (1) |
|
|
36 | (3) |
|
|
37 | (1) |
|
|
37 | (2) |
|
|
39 | (2) |
|
Chapter 3 The Concept of Inheritance |
|
|
41 | (22) |
|
|
41 | (3) |
|
|
44 | (2) |
|
|
44 | (1) |
|
|
45 | (1) |
|
|
46 | (1) |
|
|
46 | (1) |
|
|
47 | (1) |
|
|
47 | (3) |
|
|
50 | (2) |
|
|
51 | (1) |
|
|
51 | (1) |
|
|
52 | (1) |
|
|
52 | (4) |
|
|
53 | (1) |
|
|
54 | (1) |
|
|
55 | (1) |
|
|
55 | (1) |
|
|
56 | (1) |
|
|
56 | (2) |
|
|
57 | (1) |
|
|
58 | (4) |
|
|
59 | (1) |
|
|
59 | (3) |
|
|
62 | (1) |
|
Chapter 4 Get Familiar with Polymorphism |
|
|
63 | (60) |
|
|
63 | (1) |
|
|
64 | (3) |
|
|
65 | (1) |
|
|
65 | (1) |
|
|
65 | (1) |
|
|
66 | (1) |
|
|
66 | (1) |
|
|
66 | (1) |
|
|
67 | (1) |
|
|
68 | (1) |
|
|
68 | (1) |
|
|
68 | (1) |
|
|
69 | (1) |
|
|
69 | (3) |
|
|
70 | (1) |
|
|
70 | (2) |
|
|
72 | (1) |
|
|
72 | (2) |
|
A Suggestion/Good Programming Practice |
|
|
73 | (1) |
|
|
74 | (1) |
|
|
75 | (2) |
|
|
76 | (1) |
|
|
77 | (3) |
|
|
78 | (1) |
|
|
79 | (1) |
|
|
80 | (1) |
|
|
80 | (3) |
|
|
81 | (1) |
|
|
81 | (2) |
|
|
83 | (2) |
|
|
84 | (1) |
|
|
85 | (1) |
|
|
86 | (1) |
|
Experiment with Polymorphism |
|
|
86 | (1) |
|
|
86 | (3) |
|
|
88 | (1) |
|
|
88 | (1) |
|
|
89 | (3) |
|
|
90 | (1) |
|
|
90 | (2) |
|
|
92 | (3) |
|
|
94 | (1) |
|
|
94 | (1) |
|
|
95 | (1) |
|
|
95 | (1) |
|
|
95 | (2) |
|
|
96 | (1) |
|
|
97 | (1) |
|
|
97 | (1) |
|
|
97 | (1) |
|
|
98 | (3) |
|
|
99 | (1) |
|
|
99 | (1) |
|
|
100 | (1) |
|
|
100 | (1) |
|
|
100 | (1) |
|
|
100 | (1) |
|
|
101 | (2) |
|
|
102 | (1) |
|
|
103 | (1) |
|
|
103 | (3) |
|
|
105 | (1) |
|
|
106 | (2) |
|
|
107 | (1) |
|
|
107 | (1) |
|
|
108 | (2) |
|
|
109 | (1) |
|
|
109 | (1) |
|
|
110 | (1) |
|
|
110 | (2) |
|
|
111 | (1) |
|
|
112 | (11) |
|
|
113 | (1) |
|
|
114 | (1) |
|
|
115 | (1) |
|
|
115 | (3) |
|
|
118 | (1) |
|
|
119 | (1) |
|
|
119 | (1) |
|
|
120 | (2) |
|
|
122 | (1) |
|
Chapter 5 Interfaces: An Art in OOP |
|
|
123 | (22) |
|
Introduction to Interfaces |
|
|
123 | (1) |
|
|
124 | (2) |
|
|
125 | (1) |
|
|
126 | (1) |
|
|
126 | (2) |
|
|
128 | (1) |
|
|
128 | (2) |
|
|
129 | (1) |
|
|
130 | (2) |
|
|
131 | (1) |
|
|
132 | (4) |
|
|
134 | (1) |
|
|
134 | (1) |
|
|
135 | (1) |
|
|
135 | (1) |
|
Tag/Tagging/Marker Interface |
|
|
136 | (4) |
|
|
140 | (1) |
|
|
140 | (1) |
|
|
141 | (3) |
|
|
141 | (3) |
|
|
144 | (1) |
|
Chapter 6 Encapsulation with Properties and Indexers |
|
|
145 | (28) |
|
|
145 | (1) |
|
|
145 | (6) |
|
|
147 | (1) |
|
|
147 | (3) |
|
|
150 | (1) |
|
|
151 | (4) |
|
|
152 | (3) |
|
|
155 | (1) |
|
|
155 | (2) |
|
|
156 | (1) |
|
|
157 | (3) |
|
|
157 | (1) |
|
|
158 | (1) |
|
|
158 | (1) |
|
|
158 | (1) |
|
|
159 | (1) |
|
|
159 | (1) |
|
|
160 | (1) |
|
|
160 | (3) |
|
|
161 | (1) |
|
|
161 | (2) |
|
|
163 | (3) |
|
|
165 | (1) |
|
|
166 | (1) |
|
|
166 | (1) |
|
|
167 | (5) |
|
|
168 | (1) |
|
|
168 | (2) |
|
|
170 | (1) |
|
|
170 | (2) |
|
|
172 | (1) |
|
Chapter 7 Understanding Class Variables |
|
|
173 | (14) |
|
|
173 | (1) |
|
|
173 | (5) |
|
|
174 | (1) |
|
|
174 | (4) |
|
Discussions on Static Methods |
|
|
178 | (1) |
|
|
178 | (2) |
|
|
179 | (1) |
|
|
180 | (2) |
|
|
181 | (1) |
|
|
182 | (1) |
|
Discussions on Static Constructors |
|
|
182 | (1) |
|
|
183 | (3) |
|
|
184 | (1) |
|
|
184 | (2) |
|
|
186 | (1) |
|
Chapter 8 Analysis of Some Key Comparisons in C# |
|
|
187 | (44) |
|
Implicit Casting vs. Explicit Casting |
|
|
187 | (1) |
|
|
188 | (2) |
|
|
190 | (1) |
|
|
191 | (1) |
|
|
191 | (1) |
|
|
191 | (2) |
|
|
192 | (1) |
|
|
193 | (1) |
|
|
193 | (2) |
|
|
194 | (1) |
|
|
194 | (1) |
|
Upcasting vs. Downcasting |
|
|
195 | (1) |
|
|
195 | (4) |
|
|
197 | (1) |
|
|
197 | (1) |
|
|
198 | (1) |
|
|
198 | (1) |
|
|
198 | (1) |
|
|
199 | (1) |
|
Demonstration 5 The Use of the "is" Keyword |
|
|
199 | (4) |
|
|
201 | (1) |
|
|
202 | (1) |
|
|
203 | (1) |
|
Demonstration 6 The Use of the "as" Keyword |
|
|
203 | (2) |
|
|
205 | (1) |
|
|
205 | (1) |
|
Passing Value Types by Value vs. Passing Value Types by Reference (with ref vs. out) |
|
|
205 | (1) |
|
Demonstration 7 Passing Value Type by Value |
|
|
206 | (1) |
|
|
206 | (1) |
|
|
207 | (1) |
|
The ref Parameter vs. the out Parameter |
|
|
207 | (1) |
|
|
207 | (1) |
|
|
207 | (1) |
|
|
208 | (1) |
|
Demonstration 9 The Use of the "out" Parameter |
|
|
208 | (3) |
|
|
209 | (1) |
|
|
209 | (1) |
|
|
210 | (1) |
|
|
210 | (1) |
|
|
210 | (1) |
|
Demonstration 10 Passing a Reference Type as Value |
|
|
211 | (1) |
|
|
211 | (1) |
|
Demonstration 11 A Case Study with Array Elements |
|
|
212 | (3) |
|
|
213 | (1) |
|
|
213 | (1) |
|
|
214 | (1) |
|
|
215 | (1) |
|
|
215 | (1) |
|
Demonstration 12 A Method Returning Multiple Values |
|
|
215 | (1) |
|
|
216 | (1) |
|
A Brief Comparison of C# Types |
|
|
216 | (1) |
|
Value Types and Reference Types |
|
|
217 | (1) |
|
Demonstration 13 Value Types vs. Reference Types |
|
|
218 | (2) |
|
|
219 | (1) |
|
|
219 | (1) |
|
|
220 | (1) |
|
|
220 | (1) |
|
Demonstration 14 Pointer Types |
|
|
221 | (2) |
|
|
222 | (1) |
|
|
222 | (1) |
|
|
223 | (1) |
|
Demonstration 15 The Use of the "const" Keyword |
|
|
224 | (5) |
|
|
224 | (1) |
|
|
225 | (1) |
|
|
225 | (1) |
|
|
225 | (1) |
|
|
225 | (1) |
|
|
226 | (1) |
|
|
226 | (1) |
|
|
226 | (1) |
|
|
227 | (1) |
|
|
227 | (1) |
|
|
227 | (2) |
|
|
229 | (2) |
|
Chapter 9 A Quick Recap of OOP Principles in C# |
|
|
231 | (12) |
|
|
231 | (1) |
|
|
231 | (3) |
|
|
234 | (2) |
|
Demonstration 1 Composition to Handle the Preceding Problem |
|
|
236 | (2) |
|
|
238 | (1) |
|
|
238 | (1) |
|
Demonstration 2 An Aggregation Example |
|
|
238 | (4) |
|
|
240 | (1) |
|
|
241 | (1) |
|
|
241 | (1) |
|
|
242 | (1) |
|
Part II Get Familiar with Some Advanced Concepts |
|
|
243 | (130) |
|
Chapter 10 Delegates and Events |
|
|
245 | (30) |
|
Introduction to Delegates |
|
|
245 | (1) |
|
|
246 | (1) |
|
|
246 | (2) |
|
|
247 | (1) |
|
Make Your Code Size Short |
|
|
247 | (1) |
|
|
248 | (3) |
|
|
249 | (1) |
|
|
250 | (1) |
|
|
250 | (1) |
|
|
251 | (1) |
|
Multicast Delegates/Chaining Delegates |
|
|
251 | (1) |
|
|
251 | (4) |
|
|
252 | (1) |
|
|
253 | (1) |
|
|
254 | (1) |
|
|
254 | (1) |
|
Covariance and Contravariance in Delegates |
|
|
255 | (1) |
|
Covariance in Delegates/Method Group Variance |
|
|
256 | (1) |
|
|
256 | (2) |
|
|
257 | (1) |
|
|
257 | (1) |
|
Contravariance in Delegates |
|
|
257 | (1) |
|
|
258 | (2) |
|
|
259 | (1) |
|
|
259 | (1) |
|
|
260 | (2) |
|
Steps to Implement a Simple Event in C# |
|
|
261 | (1) |
|
|
262 | (2) |
|
|
263 | (1) |
|
Passing Data with Event Arguments |
|
|
264 | (1) |
|
|
265 | (2) |
|
|
267 | (1) |
|
|
267 | (1) |
|
|
267 | (3) |
|
|
270 | (4) |
|
|
273 | (1) |
|
|
274 | (1) |
|
Chapter 11 Flexibilities with Anonymous Functions |
|
|
275 | (10) |
|
Anonymous Methods and Lamda Expressions |
|
|
275 | (1) |
|
|
276 | (3) |
|
|
277 | (1) |
|
|
277 | (2) |
|
Func, Action, and Predicate Delegates |
|
|
279 | (3) |
|
|
279 | (2) |
|
|
281 | (1) |
|
|
281 | (1) |
|
|
282 | (2) |
|
|
283 | (1) |
|
|
284 | (1) |
|
|
285 | (28) |
|
Comparison between Generic and Non-Generic Programs |
|
|
285 | (1) |
|
Demonstration 1 A Non-Generic Program |
|
|
285 | (2) |
|
|
286 | (1) |
|
Demonstration 2 A Generic Program |
|
|
287 | (3) |
|
|
288 | (1) |
|
|
288 | (1) |
|
|
289 | (1) |
|
|
289 | (1) |
|
|
290 | (1) |
|
|
290 | (1) |
|
|
291 | (1) |
|
|
291 | (2) |
|
|
292 | (1) |
|
|
292 | (1) |
|
Demonstration 5 Exercise on Self-Referenced Generic Types |
|
|
293 | (2) |
|
|
295 | (1) |
|
|
295 | (1) |
|
A Special Keyword Default |
|
|
295 | (1) |
|
|
295 | (1) |
|
|
296 | (1) |
|
|
296 | (1) |
|
Demonstration 7 Assignment |
|
|
296 | (3) |
|
|
299 | (1) |
|
|
299 | (1) |
|
|
299 | (4) |
|
|
301 | (1) |
|
|
302 | (1) |
|
|
303 | (1) |
|
|
303 | (1) |
|
Covariance and Contravariance |
|
|
303 | (4) |
|
Demonstration 9 Covariance with Generic Interfaces |
|
|
307 | (2) |
|
|
309 | (1) |
|
|
309 | (1) |
|
Demonstration 10 Contravariance with Generic Delegates |
|
|
309 | (3) |
|
|
311 | (1) |
|
|
311 | (1) |
|
|
312 | (1) |
|
Chapter 13 Exception Handling |
|
|
313 | (28) |
|
Discussions on Exception Handling |
|
|
313 | (1) |
|
|
313 | (1) |
|
|
314 | (2) |
|
|
315 | (1) |
|
|
316 | (5) |
|
|
317 | (1) |
|
|
317 | (4) |
|
|
321 | (4) |
|
|
324 | (1) |
|
|
325 | (1) |
|
|
325 | (1) |
|
|
325 | (5) |
|
|
326 | (1) |
|
|
326 | (1) |
|
Other Variations of the catch Clause |
|
|
327 | (1) |
|
|
327 | (1) |
|
|
328 | (1) |
|
|
328 | (1) |
|
|
328 | (1) |
|
|
328 | (2) |
|
|
330 | (2) |
|
|
331 | (1) |
|
|
332 | (3) |
|
|
334 | (1) |
|
|
334 | (1) |
|
Creating a Custom Exception |
|
|
335 | (1) |
|
|
336 | (3) |
|
|
338 | (1) |
|
|
338 | (1) |
|
|
339 | (2) |
|
Chapter 14 Memory Cleanup |
|
|
341 | (32) |
|
How the Garbage Collector Works |
|
|
342 | (1) |
|
Three Phases of Garbage Collection |
|
|
342 | (1) |
|
Three Cases to invoke the Garbage Collector |
|
|
343 | (1) |
|
|
343 | (8) |
|
|
347 | (1) |
|
|
347 | (4) |
|
|
351 | (1) |
|
|
352 | (3) |
|
Snapshots from Diagnostic Tool |
|
|
354 | (1) |
|
|
355 | (8) |
|
Snapshots from CLR Profiler |
|
|
357 | (1) |
|
|
357 | (2) |
|
Let us modify the program |
|
|
359 | (2) |
|
|
361 | (2) |
|
|
363 | (2) |
|
|
364 | (1) |
|
|
365 | (1) |
|
|
366 | (1) |
|
|
366 | (5) |
|
|
367 | (1) |
|
|
368 | (2) |
|
|
370 | (1) |
|
|
370 | (1) |
|
|
370 | (1) |
|
|
370 | (1) |
|
|
371 | (2) |
|
Part III Become a Hero in the Real World |
|
|
373 | (36) |
|
Chapter 15 An Introduction to Design Patterns |
|
|
375 | (32) |
|
|
375 | (1) |
|
|
376 | (3) |
|
|
379 | (8) |
|
|
379 | (1) |
|
|
379 | (1) |
|
|
379 | (1) |
|
|
379 | (1) |
|
|
379 | (1) |
|
|
380 | (1) |
|
|
380 | (1) |
|
|
381 | (1) |
|
|
381 | (2) |
|
|
383 | (1) |
|
|
384 | (3) |
|
|
387 | (13) |
|
|
387 | (1) |
|
|
387 | (1) |
|
|
387 | (1) |
|
|
388 | (1) |
|
|
388 | (1) |
|
|
389 | (1) |
|
|
389 | (1) |
|
|
390 | (1) |
|
|
390 | (4) |
|
|
394 | (1) |
|
|
394 | (5) |
|
|
399 | (1) |
|
|
400 | (6) |
|
|
400 | (1) |
|
|
400 | (1) |
|
|
400 | (1) |
|
|
400 | (1) |
|
|
401 | (1) |
|
|
402 | (1) |
|
|
403 | (1) |
|
|
403 | (2) |
|
|
405 | (1) |
|
|
406 | (1) |
|
Chapter 16 Winning Notes and the Road Ahead |
|
|
407 | (2) |
|
Appendix A Collect the Raw Materials |
|
|
409 | (72) |
|
|
409 | (7) |
|
|
409 | (7) |
|
|
416 | (7) |
|
|
416 | (1) |
|
|
416 | (2) |
|
An Example of switch Statements |
|
|
418 | (5) |
|
|
423 | (8) |
|
|
424 | (1) |
|
|
425 | (6) |
|
|
431 | (4) |
|
|
431 | (4) |
|
|
435 | (2) |
|
|
437 | (12) |
|
Questions/Answers with code segments |
|
|
437 | (12) |
|
|
449 | (11) |
|
Single Dimensional Arrays |
|
|
449 | (1) |
|
|
449 | (2) |
|
|
451 | (2) |
|
|
453 | (7) |
|
|
460 | (11) |
|
|
460 | (2) |
|
|
462 | (4) |
|
|
466 | (5) |
|
|
471 | (10) |
|
|
471 | (1) |
|
|
472 | (9) |
|
|
481 | (6) |
|
|
487 | (2) |
Index |
|
489 | |