Skip to content

Commit 086aeab

Browse files
committed
Added VS code formatting screenshot
1 parent 5f52838 commit 086aeab

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ The first thing that we see is **the curly brackets `{}`**. The first (opening)
4242

4343
The same rule applies for **the `for` loops and all other constructions with curly brackets `{}`**. Here are some more examples:
4444

45-
**Correct**:
45+
**Correct** formatting:
4646
```csharp
4747
for (int i = 0; i < 5; i++)
4848
{
4949
Console.WriteLine(i);
5050
}
5151
```
5252

53-
**Wrong**:
53+
**Wrong** formatting:
5454
```csharp
5555
for(int i=0;i<5;i++){
5656
Console.WriteLine(i);
@@ -61,13 +61,18 @@ Console.WriteLine(i);
6161

6262
For your comfort there are **keyboard shortcuts in Visual Studio**, which we will explain later in this chapter, but for now we are interested in 2 specific combinations. One of the combinations is for formatting **the code in the whole document**, and the other one – for formatting **a part of the code**. If we want to format **the whole code**we need to press [**CTRL + K + D**]. In case we need to format only **a part of the code**, we need to **mark this part with the mouse** and press [**CTRL + K + F**].
6363

64-
Let's use **the wrong example** from earlier:
64+
The screenshot below illustrates how to **format C# code in Visual Studio**, using the menu commands or keyboard schortcuts:
65+
66+
![](/assets/chapter-11-images/00.Code-formatting.png)
67+
68+
Let's use **the wrongly formatted example** from earlier:
6569

6670
```csharp
6771
for(int i=0;i<5;i++){
6872
Console.WriteLine(i);
6973
}
7074
```
75+
7176
If we press [**CTRL + K + D**], which is the combination to **format the whole document**, we will have a code, formatted according to **the accepted conventions for C#**, which will look as follows:
7277

7378
```csharp
@@ -76,4 +81,5 @@ for (int i = 0; i < 5; i++)
7681
Console.WriteLine(i);
7782
}
7883
```
79-
This key combination can help us if we found a badly formatted code.
84+
85+
This key combination in Visual Studio can help us if we work with a badly formatted code.
35.2 KB
Loading

0 commit comments

Comments
 (0)