Skip to content

Commit 4acc228

Browse files
committed
fixes and improvements
1 parent f5f65d6 commit 4acc228

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed

Content/Chapter-11-tricks-and-hacks/code-snippets/code-snippets.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,15 @@ We see many things we haven't seen yet, but don't worry, we will become acquaint
3030

3131
## Changing an Existing Snippet
3232

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:
3442

3543
![](/assets/chapter-11-images/01.Code-snippet-05.jpg)
3644

@@ -42,7 +50,6 @@ After we have written our snippet, we should **save the file in format** `snippe
4250

4351
![](/assets/chapter-11-images/01.Code-snippet-08.jpg)
4452

45-
Now when we write `cr` in Visual Studio, **our new snippet** appears:
53+
Now when we write `cr`” and press **[Tab]** twice in Visual Studio, **our new snippet** will appear, as it is shown in the screenshot below:
4654

4755
![](/assets/chapter-11-images/01.Code-snippet-07.jpg)
48-

Content/Chapter-11-tricks-and-hacks/tricks/tricks.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
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.
44

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.
68

79
```csharp
810
var text = "some text";
@@ -23,16 +25,19 @@ In this example we can see that we can insert **not only text variables**. We ca
2325

2426
## Formatting with 2 Digits After the Decimal Point
2527

28+
When we print numbers, we often need to round them to 2 digits after the decimal point, e.g.
29+
2630
```csharp
2731
var number = 5.432432;
2832
Console.WriteLine(Math.Round(number, 2));
2933
// This will print on the console "5.43"
3034
```
3135

32-
`Math.Round(…)` takes 2 parameters:
36+
## Rounding Numbers
3337

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)
3641

3742
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:
3843

@@ -74,7 +79,9 @@ The conditional `if`** construction** contains the following elements:
7479
* Keyword `if`
7580
* **A Boolean expression** \(condition\)
7681
* **Body** of the conditional construction
77-
* Optional: `else`** clause**
82+
* Optional: **`else` clause**
83+
84+
Example:
7885

7986
```csharp
8087
if (condition)
@@ -87,18 +94,18 @@ else (condition)
8794
}
8895
```
8996

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**:
9198

9299
* `if`** + \[Tab\] + \[Tab\]**
93100

94101
## How to Write a 'For' Loop?
95102

96-
For a `for`** loop** we need a couple of things:
103+
For a **`for` loop** we need a couple of things:
97104

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
106+
- **Condition** for repetition (`i <= 10`)
107+
- Loop variable (counter) **updating statement** (`i++`)
108+
- **Body** of the loop, holding statements
102109

103110
```csharp
104111
for (var i = 0; i < 5; i++;)

Content/Chapter-11-tricks-and-hacks/visual-studio-shortcuts/visual-studio-shortcuts.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
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.
44

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**:
66

77
| Combination | Action|
88
| --- | --- |
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**. |
1010
| [**CTRL + K + C**] | **Comments** part of the code. |
1111
| [**CTRL + K + U**] | **Uncomments a code**, which is already commented. |
1212
| [**CTRL + Z**] | **Brings back one change** (so-called Undo). |

0 commit comments

Comments
 (0)