From a58a74a3e5d3879c9b06cf1ecb813bd68f64c6d6 Mon Sep 17 00:00:00 2001 From: Randy8080 Date: Fri, 14 Jan 2022 09:39:27 +0800 Subject: [PATCH] Reformat c# --- cs.md | 134 ++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 84 insertions(+), 50 deletions(-) diff --git a/cs.md b/cs.md index ca4e5b7..e28f758 100644 --- a/cs.md +++ b/cs.md @@ -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} + +