You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Content/Chapter-11-tricks-and-hacks/code-snippets/code-snippets.md
+10-3Lines changed: 10 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -30,7 +30,15 @@ We see many things we haven't seen yet, but don't worry, we will become acquaint
30
30
31
31
## Changing an Existing Snippet
32
32
33
-
Now we have to focus on the part `<Title></Title>`, `<Shortcut></Shortcut>` and the code between `CDATA[]`. Firstly, we will change the title in `<Title></Title>` and in the place of `cw`we will write `cr`, as this will be **the title of our snippet**. After that, in the section `<Shortcut></Shortcut>`, we will change what we have to write to **call our snippet**\(the shortcut\) from `cw` to `cr`. Finally, we need to change the code in `CDATA[]`, from `WriteLine` to `ReadLine`: `CDATA[$SystemConsole$.ReadLine($end$);]`. If you wish, you can change the sections `<Description></Description>` and `<Author></Author>`. The changed file should look like this:
33
+
To create a new snipped, we shall take an existing snipped, modify it and save it in a new snipped file.
34
+
35
+
We have to focus on the part `<Title></Title>`, `<Shortcut></Shortcut>` and the code between `CDATA[]`.
36
+
- Firstly, we will change the title in `<Title></Title>` and in the place of `cw`we will write `cr`, as this will be **the title of our snippet**.
37
+
- After that, in the section `<Shortcut></Shortcut>`, we will change what we have to write to **call our snippet**\(the shortcut\) from `cw` to `cr`.
38
+
- Finally, we need to change the code in `CDATA[]`, from `WriteLine` to `ReadLine`: `CDATA[$SystemConsole$.ReadLine($end$);]`.
39
+
- If you wish, you can change the sections `<Description></Description>` and `<Author></Author>`.
40
+
41
+
The changed file, after all described modifications, should look like this:
Copy file name to clipboardExpand all lines: Content/Chapter-11-tricks-and-hacks/tricks/tricks.md
+18-11Lines changed: 18 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,9 @@
2
2
3
3
In this section we will recall some **tricks and techniques** in programming with C\#, already seen in this book, which can be very useful if you attend an exam for beginner programming.
4
4
5
-
## Inserting Variables in Strings
5
+
## Inserting Variable Values in Strings
6
+
7
+
In programming we often need to **combine text with variable values** to obtain a string value, e.g.
6
8
7
9
```csharp
8
10
vartext="some text";
@@ -23,16 +25,19 @@ In this example we can see that we can insert **not only text variables**. We ca
23
25
24
26
## Formatting with 2 Digits After the Decimal Point
25
27
28
+
When we print numbers, we often need to round them to 2 digits after the decimal point, e.g.
29
+
26
30
```csharp
27
31
varnumber=5.432432;
28
32
Console.WriteLine(Math.Round(number, 2));
29
33
// This will print on the console "5.43"
30
34
```
31
35
32
-
`Math.Round(…)` takes 2 parameters:
36
+
## Rounding Numbers
33
37
34
-
* the first one is **the number we want to round**
35
-
* the second one is the number that determines **how many digits after the decimal point we want to round to**\(this should always be an integer\)
38
+
To round numbers, we may use the `Math.Round(…)` method, which takes 2 parameters:
39
+
- the first one is **the number we want to round**
40
+
- the second one is the number that determines **how many digits after the decimal point we want to round to** (this should always be an integer)
36
41
37
42
If we want to round the number to **2 digits after the decimal point** and the third digit is lower than 5, as in the example above, the rounding is down, but if the third digit is equal or bigger than 5 – the rounding is up as in the example below:
38
43
@@ -74,7 +79,9 @@ The conditional `if`** construction** contains the following elements:
74
79
* Keyword `if`
75
80
***A Boolean expression**\(condition\)
76
81
***Body** of the conditional construction
77
-
* Optional: `else`** clause**
82
+
* Optional: **`else` clause**
83
+
84
+
Example:
78
85
79
86
```csharp
80
87
if (condition)
@@ -87,18 +94,18 @@ else (condition)
87
94
}
88
95
```
89
96
90
-
To make it easier we can use a code snippet for an `if`** construction**:
97
+
To make it easier we can use a code snippet for an **`if` construction**:
91
98
92
99
*`if`** + \[Tab\] + \[Tab\]**
93
100
94
101
## How to Write a 'For' Loop?
95
102
96
-
For a `for`** loop** we need a couple of things:
103
+
For a **`for` loop** we need a couple of things:
97
104
98
-
*Initializing block, in which the counting variable is declared \(`var i`\) and its initial value is set.
99
-
*Condition for repetition \(`i <= 10`\).
100
-
* Renewing the counter\(`i++`\).
101
-
*Body of the loop.
105
+
-**Initializing block**, in which the counter variable is declared (`var i`) and its initial value is set
Copy file name to clipboardExpand all lines: Content/Chapter-11-tricks-and-hacks/visual-studio-shortcuts/visual-studio-shortcuts.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -2,11 +2,11 @@
2
2
3
3
In the previous section we mentioned two of the combinations that are used for formatting code. One of them [**CTRL + K + D**] is used for **formatting the whole code in a file**, and the second one [**CTRL + K + F**] serves if we want to **format just a piece of the code**. These combinations are called **shortcuts** and now we will give more thorough information about them.
4
4
5
-
Shortcuts are **combinations** that give us the possibility to do some things in an **easier and faster** way, and each IDE has its shortcuts, even though most of them are recurring. Now we will look at some of the **shortcuts** in **Visual Studio**.
5
+
Shortcuts are **combinations** that give us the possibility to do some things in an **easier and faster** way, and each IDE has its shortcuts, even though most of them are recurring. Now we will look at some of the **shortcuts** in **Visual Studio**:
6
6
7
7
| Combination | Action|
8
8
| --- | --- |
9
-
|[**CTRL + F**]|The combination**opens the search window**, by which we can **search in our code**. |
9
+
|[**CTRL + F**]|Opens the**search window**, by which we can **search in our code**. |
10
10
|[**CTRL + K + C**]|**Comments** part of the code. |
11
11
|[**CTRL + K + U**]|**Uncomments a code**, which is already commented. |
12
12
|[**CTRL + Z**]|**Brings back one change** (so-called Undo). |
0 commit comments