-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday1.html
More file actions
353 lines (353 loc) · 13.4 KB
/
day1.html
File metadata and controls
353 lines (353 loc) · 13.4 KB
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
<!DOCTYPE HTML>
<html lang="de">
<head>
<title>Programming C#</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=1274, user-scalable=no">
<link rel="stylesheet" href="themes/styles/style.css">
</head>
<body class="list">
<header class="caption">
<h1>Programming C#</h1>
</header>
<div class="slide cover" id="Cover"><div>
<section>
<header>
<h2>Programming C#</h2>
<h3>Day 1: Basic concepts, types, arrays, properties and Console projects</h3>
</header>
<img src="pictures/cover.jpg" alt="">
</section>
</div></div>
<div class="slide" id="overview"><div>
<section>
<header>
<h2>Content</h2>
</header>
<ul>
<li>The Microsoft Visual Studio</li>
<li>Basic concepts and syntax</li>
<li>The C# type system</li>
<li>Arrays, Lists, Dictionaries</li>
<li>Constants</li>
<li>Function overloading and generic functions</li>
<li>C# projects and debugging</li>
<li>Writing and running console projects</li>
</ul>
</section>
</div></div>
<div class="slide" id="microsoft-vs"><div>
<section>
<header>
<h2>Micosoft Visual Studio (VS)</h2>
</header>
<ul>
<li>Multiple ways to write C#</li>
<li>The most elegant and efficient is probably using VS</li>
<li>CIP Pool has version 2010 (2012 would be better)</li>
<li>Integrated project management, debugging, profiling, ...</li>
<li>Most important: File, New Project, C#, Console project</li>
</ul>
</section>
</div></div>
<div class="slide" id="console"><div>
<section>
<header>
<h2>Console projects</h2>
</header>
<ul>
<li>No GUI, just the plain Windows command line</li>
<li>All possibilities given in the <code>Console</code> class</li>
<li>Possible to pass arbitrary objects to <code>Console.Write()</code></li>
<li>Reason: Every class inherits from <code>object</code> and has <code>ToString()</code></li>
<li>Possibility of formatting strings with placeholders <code>{0}</code> etc.</li>
<li>Use <code>ReadLine()</code> to read string until <i>RETURN</i></li>
</ul>
</section>
</div></div>
<div class="slide" id="basic-concepts-1"><div>
<section>
<header>
<h2>Basic concepts of C# (pt. 1)</h2>
</header>
<ul>
<li>C# (out-of-the-box) is not native and not interpreted</li>
<li>Programs are saved in an intermediate language</li>
<li>That makes C# universal (same concept as Java)</li>
<li>C# is also managed code, i.e. no control over memory</li>
<li>C# is a strongly-typed language with a static type system</li>
<li>This means that types must be identified at compilation</li>
<li>Encapsulation required, i.e. every function is assigned to a class</li>
</ul>
</section>
</div></div>
<div class="slide" id="garbage-collection"><div>
<section>
<header>
<h2>How Garbage Collection works</h2>
</header>
<img src="pictures/gc.png" class="middle r" />
</section>
</div></div>
<div class="slide" id="basic-concepts-2"><div>
<section>
<header>
<h2>Basic concepts of C# (pt. 2)</h2>
</header>
<ul>
<li>Just two datatypes: <code>struct</code> and <code>class</code></li>
<li>Structures are value types (only copies are passed)</li>
<li>Classes are reference types (references are passed)</li>
<li>The concept of a pointer is embedded in the language</li>
<li>Passing structures by reference is possible with the <code>ref</code> keyword</li>
<li>Another way is the <code>out</code> keyword (enforces assignment)</li>
<li>Every object inherits at least from another object called <code>object</code></li>
</ul>
</section>
</div></div>
<div class="slide" id="basic-concepts-3"><div>
<section>
<header>
<h2>Basic concepts of C# (pt. 3)</h2>
</header>
<ul>
<li>The syntax is quite close to C++ / Java</li>
<li>Datatypes have to be specified</li>
<li>Example: Due to encapsulation all console related functions can be found in the static class <code>Console</code>, which is located in the <code>System</code> namespace</li>
<li>Why static class? Closest to C <code>printf()</code>, <code>scanf()</code>, ...</li>
<li>Namespaces guarantee overview and unique naming</li>
</ul>
</section>
</div></div>
<div class="slide" id="namespaces"><div>
<section>
<header>
<h2>What are namespaces?</h2>
</header>
<img src="pictures/worldmap.jpg" class="w">
</section>
</div></div>
<div class="slide" id="example-hello-world"><div>
<section>
<header>
<h2 class="example">→ Example - Hello World!</h2>
</header>
<a href="https://github.com/CSharpLecture/Samples/blob/master/day1/HelloWorld.cs" title="Download source" class="example-download">HelloWorld.cs</a>
</section>
</div></div>
<div class="slide" id="syntax-1"><div>
<section>
<header>
<h2>Syntax of C# (pt. 1)</h2>
</header>
<ul>
<li>Example is quite close to C++</li>
<li>Differences: <code>using</code> for embedding namespaces</li>
<li>The main method has to be specified differently</li>
<li>We have <code>static void Main(string[] args)</code></li>
<li>Array datatype has already a field to specify the length</li>
<li>No header files and macros</li>
<li><code>if</code>, <code>else</code>, <code>for</code>, ... as in C++</li>
<li>Additionally we have <code>foreach</code> and <code>lock</code></li>
</ul>
</section>
</div></div>
<div class="slide" id="syntax-2"><div>
<section>
<header>
<h2>Syntax of C# (pt. 2)</h2>
</header>
<ul>
<li>The dot operator lets use access the members of an object</li>
<li>Constants need to be defined using <code>const</code> and a type</li>
<li>Only structures can be constants, otherwise use <code>readonly</code></li>
<li>Arrays are defined different than in C/C++</li>
<li>However, accessing arrays is the same as in C/C++</li>
<li>Several literals for creating types, like <code>"hello"</code> is a string type, <code>'C'</code> is a new char, <code>4</code> a new integer and <code>4.0</code> a new double</li>
</ul>
</section>
</div></div>
<div class="slide" id="example-control-flow"><div>
<section>
<header>
<h2 class="example">→ Example - Control flow</h2>
</header>
<a href="https://github.com/CSharpLecture/Samples/blob/master/day1/ControlFlow.cs" title="Download source" class="example-download">ControlFlow.cs</a>
<a href="https://github.com/CSharpLecture/Samples/blob/master/day1/Foreach.cs" title="Download source" class="example-download">Foreach.cs</a>
</section>
</div></div>
<div class="slide" id="datatypes"><div>
<section>
<header>
<h2>Datatypes</h2>
</header>
<ul>
<li>Some basic structures (size in bytes): <code>char</code> (2), <code>short</code> (2), <code>int</code> (4), <code>long</code> (8), <code>float</code> (4), <code>double</code> (8), <code>decimal</code> (16), <code>bool</code> (1)</li>
<li>Some important classes: <code>string</code>, <code>Array</code>, <code>ArrayList</code>, <code>Stack</code>, <code>Queue</code></li>
<li>We have <code>enum</code>, <code>struct</code>, <code>class</code>, <code>interface</code>, <code>delegate</code> to create new data types</li>
<li>An enumeration is a collection of constants</li>
<li>A delegate is a managed function pointer</li>
</ul>
</section>
</div></div>
<div class="slide" id="operators"><div>
<section>
<header>
<h2>Operators</h2>
</header>
<ul>
<li>C# supports the same standard operators as C++</li>
<li>Overloading is only possible for certain operators</li>
<li>The execution hierachy is determined by the operator</li>
<li>Changing the hierachy is possible by using brackets</li>
<li>A selection of operators: <code>+</code>, <code>-</code>, <code>*</code>, <code>/</code>, <code>%</code>, <code>!</code>, <code><</code>, <code>></code>, <code>==</code>, <code>!=</code>, <code><<</code>, <code>>></code>, ...</li>
</ul>
</section>
</div></div>
<div class="slide" id="example-datatypes-operators"><div>
<section>
<header>
<h2 class="example">→ Example - Datatypes and operators</h2>
</header>
<a href="https://github.com/CSharpLecture/Samples/blob/master/day1/samples/DataTypes.cs" title="Download source" class="example-download">DataTypes.cs</a>
</section>
</div></div>
<div class="slide" id="arrays"><div>
<section>
<header>
<h2>Arrays</h2>
</header>
<ul>
<li>A simple array of integers: <code>int[] myarray = new int[5];</code></li>
<li>Initialization <code>char[] arr = new char[] { 'a', 'b', 'c' }</code></li>
<li>Modification <code>arr[2] = 'd'</code> (0-based !)</li>
<li>More-dimensional: <code>double[,] matrix = new double[5,5];</code></li>
<li>Access <code>Console.WriteLine("M_33 = " + matrix[2,2])</code></li>
<li>It is also possible to use jagged arrays like so:
<pre>
<code>double[][] matrix = new double[5][];</code>
<code>matrix[0] = new double[5]; // ...</code>
</pre>
</li>
</ul>
</section>
</div></div>
<div class="slide" id="collections"><div>
<section>
<header>
<h2>Collections</h2>
</header>
<ul>
<li>The .NET-Framework contains a huge number of collections</li>
<li>Collections go beyond the fixed limits of arrays</li>
<li>With OOP it is easily possible to create own implementations</li>
<li>Some collections are obvious (Dictionaries, Hashtables, Lists) others more specialized (Stack, Queue)</li>
<li>The <code>ArrayList</code> object is one of the simplest implementations</li>
<li>It takes only types of type <code>object</code></li>
</ul>
</section>
</div></div>
<div class="slide" id="example-arrays"><div>
<section>
<header>
<h2 class="example">→ Example - Arrays and collections</h2>
</header>
<a href="https://github.com/CSharpLecture/Samples/blob/master/day1/Arrays.cs" title="Download source" class="example-download">Arrays.cs</a>
</section>
</div></div>
<div class="slide" id="more-features"><div>
<section>
<header>
<h2>What else?</h2>
</header>
<ul>
<li>The basic datatypes have useful helper functions and members</li>
<li>Examples are: <code>double.TryParse()</code>, <code>int.MaxValue</code></li><br>
<li>Functions can accept many input parameters by use of the <code>params</code> keyword</li><br>
<li>Enumerations can be formatted with a nice string representation using the <code>Flags</code> attribute</li>
</ul>
</section>
</div></div>
<div class="slide" id="generic-methods"><div>
<section>
<header>
<h2>Generic methods</h2>
</header>
<ul>
<li>Functions are defined by their attributes and can be overloaded</li>
<li>Alternatively: Generics is a way of reusing code</li>
<!--<li>Not only classes can be generated, also methods</li>-->
<!--<li>Similar syntax, but (mostly) different (easier) usage</li>-->
<li>For methods the compiler can (mostly) infer the type</li>
<li>In the following example also note the use of <code>ref</code></li>
</ul>
<pre><code>public static void <mark>Swap<mark class="important"><T></mark></mark>(ref T l, ref T r) {</code>
<code> T temp = r; r = l; l = temp;</code>
<code>}</code>
<code>int a = 3; int b = 4; <mark>Swap</mark>(ref a, ref b);</code></pre>
</section>
</div></div>
<div class="slide" id="debugging"><div>
<section>
<header>
<h2>Debugging</h2>
</header>
<ul>
<li>Debugging is great with the VS</li>
<li>Remember: <i>F5</i> to start debugging</li>
<li><i>CTRL+F5</i> to start the project</li>
<li>Insert breakpoints to see what's going on</li>
<li>While debugging: <i>F10</i> to step over, <i>F11</i> to step into</li>
<li>Step out of the current function with <i>SHIFT+F11</i></li>
<li>More possibilites (watches, locals, interaction, ...)</li>
</ul>
</section>
</div></div>
<div class="slide" id="advanced-debugging"><div>
<section>
<header>
<h2>Advanced debugging</h2>
</header>
<ul>
<li>Never use a <code>MessageBox</code> or the <code>Console</code> for debugging</li>
<li>Best options: <code>Debug</code> or <code>Trace</code></li>
<li>Here output will be send to the output window</li>
<li>They are only used if certain definitions are active</li>
<li>Also remember that we have the <code>DEBUG</code> definition in debug-mode</li>
<li>Recommendation: Just use <code>Debug.WriteLine()</code></li>
<li>Also use breakpoints and (advanced) conditional breakpoints</li>
<li>Use the stack-trace for navigation</li>
</ul>
</section>
</div></div>
<div class="slide" id="presentations"><div>
<section>
<header>
<h2>All available presentations</h2>
</header>
<div class="left">
<b>Week 1</b>
<ul>
<li><a href="day1.html">Presentation of Monday</a></li>
<li><a href="day2.html">Presentation of Tuesday</a></li>
<li><a href="day3.html">Presentation of Wednesday</a></li>
<li><a href="day4.html">Presentation of Thursday</a></li>
<li><a href="day5.html">Presentation of Friday</a></li>
</ul>
</div>
<div class="right">
<b>Week 2</b>
<ul>
<li><a href="day6.html">Presentation of Monday</a></li>
<li><a href="day7.html">Presentation of Tuesday</a></li>
<li><a href="day8.html">Presentation of Wednesday</a></li>
<li><a href="day9.html">Presentation of Thursday</a></li>
</ul>
</div>
</section>
</div></div>
<div class="progress"><div></div></div>
<script src="scripts/script.js"></script>
<!-- Copyright © 2013 Florian Rappl, www.florian-rappl.de -->
</body>
</html>