mirror of
https://github.com/Fechin/reference.git
synced 2026-11-21 21:44:45 +03:00
Reformat c#
This commit is contained in:
1 parent
3722bcf89b
commit
a58a74a3e5
1 file changed
+84
-50
@@ -16,7 +16,7 @@ intro: |
|
||||
Getting started {.cols-3}
|
||||
--------
|
||||
|
||||
### Hello.cs {.row-span-2}
|
||||
### Hello.cs
|
||||
```cs
|
||||
class Hello {
|
||||
// main method
|
||||
@@ -33,22 +33,6 @@ $ dotnet run
|
||||
Hello, world!
|
||||
```
|
||||
|
||||
### Comments
|
||||
```cs
|
||||
// Single-line comment
|
||||
|
||||
/* Multi-line
|
||||
comment */
|
||||
|
||||
// TODO: Adds comment to a task list in Visual Studio
|
||||
|
||||
/// Single-line comment used for documentation
|
||||
|
||||
/** Multi-line comment
|
||||
used for documentation **/
|
||||
|
||||
```
|
||||
|
||||
|
||||
### Variables
|
||||
```cs
|
||||
@@ -81,6 +65,24 @@ var bo = false;
|
||||
{.show-header}
|
||||
|
||||
|
||||
|
||||
### Comments
|
||||
```cs
|
||||
// Single-line comment
|
||||
|
||||
/* Multi-line
|
||||
comment */
|
||||
|
||||
// TODO: Adds comment to a task list in Visual Studio
|
||||
|
||||
/// Single-line comment used for documentation
|
||||
|
||||
/** Multi-line comment
|
||||
used for documentation **/
|
||||
|
||||
```
|
||||
|
||||
|
||||
### Strings
|
||||
```cs
|
||||
string first = "John";
|
||||
@@ -90,37 +92,7 @@ string last = "Doe";
|
||||
string name = first + " " + last;
|
||||
Console.WriteLine(name); // => John Doe
|
||||
```
|
||||
---
|
||||
```cs
|
||||
// string interpolation
|
||||
string name = $"{first} {last}";
|
||||
Console.WriteLine(name); // => John Doe
|
||||
```
|
||||
---
|
||||
```cs
|
||||
// verbatim strings
|
||||
string longString = @"I can type any characters in here !#@$%^&*()__+ '' \n \t except double quotes and I will be taken literally. I even work with multiple lines.";
|
||||
```
|
||||
#### String Members
|
||||
```cs
|
||||
// Using property of System.String
|
||||
string lengthOfString = "How long?";
|
||||
Console.WriteLine(lengthOfString.Length); // => 9
|
||||
|
||||
// Using methods of System.String
|
||||
Console.WriteLine(lengthOfString.Contains("How")); // => true
|
||||
```
|
||||
| String Member | Description |
|
||||
|---------------|-------------|
|
||||
| Length | A property that returns the length of the string. |
|
||||
| Compare() | A static method that compares two strings. |
|
||||
| Contains() | Determines if the string contains a specific substring. |
|
||||
| Equals() | Determines if the two strings have the same character data. |
|
||||
| Format() | Formats a string via the {0} notation and by using other primitives. |
|
||||
| Trim() | Removes all instances of specific characters from trailing and leading characters. Defaults to removing leading and trailing spaces. |
|
||||
| Split() | Removes the provided character and creates an array out of the remaining characters on either side. |
|
||||
{.show-header}
|
||||
|
||||
See: [Strings](#c-strings)
|
||||
|
||||
### User Input
|
||||
```cs
|
||||
@@ -174,12 +146,74 @@ foreach(int num in numbers) {
|
||||
}
|
||||
```
|
||||
|
||||
### General .NET Terms
|
||||
|
||||
|
||||
|
||||
|
||||
C# Strings {.cols-3}
|
||||
----------------
|
||||
|
||||
### String concatenation
|
||||
```cs
|
||||
string first = "John";
|
||||
string last = "Doe";
|
||||
|
||||
string name = first + " " + last;
|
||||
Console.WriteLine(name); // => John Doe
|
||||
```
|
||||
|
||||
### String interpolation
|
||||
```cs
|
||||
string first = "John";
|
||||
string last = "Doe";
|
||||
|
||||
string name = $"{first} {last}";
|
||||
Console.WriteLine(name); // => John Doe
|
||||
```
|
||||
|
||||
### String Members {.row-span-2}
|
||||
| Member | Description |
|
||||
|------------ |-------------|
|
||||
| Length | A property that returns the length of the string. |
|
||||
| Compare() | A static method that compares two strings. |
|
||||
| Contains() | Determines if the string contains a specific substring. |
|
||||
| Equals() | Determines if the two strings have the same character data. |
|
||||
| Format() | Formats a string via the {0} notation and by using other primitives. |
|
||||
| Trim() | Removes all instances of specific characters from trailing and leading characters. Defaults to removing leading and trailing spaces. |
|
||||
| Split() | Removes the provided character and creates an array out of the remaining characters on either side. |
|
||||
{.show-header}
|
||||
|
||||
|
||||
### Verbatim strings
|
||||
```cs {.wrap}
|
||||
string longString = @"I can type any characters in here !#@$%^&*()__+ '' \n \t except double quotes and I will be taken literally. I even work with multiple lines.";
|
||||
```
|
||||
|
||||
|
||||
### Member Example
|
||||
```cs
|
||||
// Using property of System.String
|
||||
string lengthOfString = "How long?";
|
||||
lengthOfString.Length // => 9
|
||||
|
||||
// Using methods of System.String
|
||||
lengthOfString.Contains("How"); // => true
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
Misc {.cols-3}
|
||||
-----------
|
||||
|
||||
### General .NET Terms {.col-span-2}
|
||||
|
||||
| Term | Definition |
|
||||
|------------|------------|
|
||||
| Runtime | A collection of services that are required to execute a given compiled unit of code. |
|
||||
| Common Language Runtime (CLR) | Primarily locates, loads, and managed .NET objects. The CLR also handles memory management, application hosting, coordination of threads, performaing security checks, and other low-level details. |
|
||||
| Managed code | Code that compiles and runs on .NET runtime. C#/F#/VB are examples. |
|
||||
| Umanaged code | Code that compiles straight to machine code and cannot be directly hosted by the .NET runtime. Contains no free memory management, garbage collection, etc. DLLs created from C/C++ are examples. |
|
||||
| Unmanaged code | Code that compiles straight to machine code and cannot be directly hosted by the .NET runtime. Contains no free memory management, garbage collection, etc. DLLs created from C/C++ are examples. |
|
||||
{.show-header}
|
||||
|
||||
|
||||
Reference in new issue
Block a user