Merge pull request #131 from bradgermain/main

Created general terms, comments for C#, fixes, and updates to strings
This commit is contained in:
Randy8080 authored and GitHub committed 2022-01-14 09:24:10 +08:00
commit 3722bcf89b
1 file changed
+56 -5
+56 -5
View File
@@ -33,6 +33,22 @@ $ 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
@@ -70,15 +86,40 @@ var bo = false;
string first = "John";
string last = "Doe";
// string concatenation
string name = first + " " + last;
Console.WriteLine(name); // => John Doe
```
---
```
// Or string interpolation
string name = $"{first} {last}"
```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}
### User Input
@@ -127,8 +168,18 @@ for(int i = 0; i < numbers.Length; i++) {
}
```
---
```
```cs
foreach(int num in numbers) {
Console.WriteLine(num);
}
```
```
### General .NET Terms
| 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. |
{.show-header}