From 3e75ce3aadeec02f45feda13d944b23cb845acf2 Mon Sep 17 00:00:00 2001 From: Stone-Red-Code <56473591+Stone-Red-Code@users.noreply.github.com> Date: Thu, 8 Jul 2021 19:27:21 +0200 Subject: [PATCH] Basic resources added - intro - naming conventions - access modifiers --- .../language/c-sharp/access-modifiers.md | 23 +++ .../language/c-sharp/coding-conventions.md | 135 ++++++++++++++++++ .../resources/language/c-sharp/intro.md | 27 ++++ 3 files changed, 185 insertions(+) create mode 100644 src/content/resources/language/c-sharp/access-modifiers.md create mode 100644 src/content/resources/language/c-sharp/coding-conventions.md create mode 100644 src/content/resources/language/c-sharp/intro.md diff --git a/src/content/resources/language/c-sharp/access-modifiers.md b/src/content/resources/language/c-sharp/access-modifiers.md new file mode 100644 index 0000000..040cfe8 --- /dev/null +++ b/src/content/resources/language/c-sharp/access-modifiers.md @@ -0,0 +1,23 @@ +--- +authors: + - "Stone_Red#2890" +created_at: 2021/08/07 +title: C# +external_resources: + - text: Access Modifiers + href: "https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/access-modifiers" +--- + +## Availible access modifiers + +- **public:** The type or member can be accessed by any other code in the same assembly or another assembly that references it. +- **private:** The type or member can be accessed only by code in the same class or struct. +- **protected:** The type or member can be accessed only by code in the same class, or in a class that is derived from that class. +- **internal:** The type or member can be accessed by any code in the same assembly, but not from another assembly. +- **protected internal:** The type or member can be accessed by any code in the assembly in which it's declared, or from within a derived class in another assembly. +- **private protected:** The type or member can be accessed only within its declaring assembly, by code in the same class or in a type that is derived from that class. + +## Why not use _public_ for everything? + +Access modifiers control where members can be accessed and seen. +If you were to make everything _public_, anyone could access the member without restrictions and possibly change variables to undesired values or call methods that should only be called on certain events. diff --git a/src/content/resources/language/c-sharp/coding-conventions.md b/src/content/resources/language/c-sharp/coding-conventions.md new file mode 100644 index 0000000..16b9f5b --- /dev/null +++ b/src/content/resources/language/c-sharp/coding-conventions.md @@ -0,0 +1,135 @@ +--- +authors: + - "Stone_Red#2890" +created_at: 2021/08/07 +title: C# +external_resources: + - text: Coding Conventions + href: "https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style/coding-conventions" +--- + +## Naming conventions + +Coding conventions serve the following purposes: + +- They create a consistent look to the code, so that readers can focus on content, not layout. +- They enable readers to understand the code more quickly by making assumptions based on previous experience. +- They facilitate copying, changing, and maintaining the code. +- They demonstrate C# best practices. + +### Pascal case + +Use pascal casing ("PascalCasing") when naming a class, record, interface or struct. + +```cs +public class MessageService +{ +} +``` + +```cs +public record Temperature(double HighTemp, double LowTemp); +``` + +```cs +public interface ISampleInterface +{ +} +``` + +```cs +public struct Coordinate +{ +} +``` + +### Camel case + +Use camel casing ("camelCasing") when naming private or internal fields. + +```cs +public class DataService +{ + private IWorkerQueue _workerQueue; +} +``` + +When writing method parameters or local varibles, use camel casing. + +```cs +public void SampleMethod(string name, int age) +{ + int index = 0; +} +``` + +### Additional naming conventions + +Do not use Hungarian notation or any other type identification in identifiers. + +```cs +//Do: +int age; +string name; +//Don't: +int iAge; +string strName; +``` + +Use meaningful names for variables. + +```cs +//Do: +string factoryName; +int age; +//Don't +string str; +int i; +``` + +Do use prefix Any, Is, Have or similar keywords for boolean identifier. + +```cs +public bool IsAvailable() +{ +} +``` + +## Layout conventions + +- Use the default Code Editor settings (smart indenting, four-character indents, tabs saved as spaces). For more information, see Options, Text Editor, C#, Formatting. +- Write only one statement per line. +- Write only one declaration per line. +- If continuation lines are not indented automatically, indent them one tab stop (four spaces). +- Add at least one blank line between method definitions and property definitions. +- Use parentheses to make clauses in an expression apparent, as shown in the following code. + +## Commenting conventions + +- Place the comment on a separate line, not at the end of a line of code. +- Begin comment text with an uppercase letter. +- End comment text with a period. +- Insert one space between the comment delimiter (//) and the comment text, as shown in the following example + +```cs +string password = Console.ReadLine(); +if(password == "1234") +{ + Console.WriteLine("Correct password!"); +} +``` + +```cs +//Do: + +/// Calculates something. +public int Calculate() +{ +} + +//Don't: + +public int Calculate() //Calculates something +{ +} +``` diff --git a/src/content/resources/language/c-sharp/intro.md b/src/content/resources/language/c-sharp/intro.md new file mode 100644 index 0000000..9e97ad0 --- /dev/null +++ b/src/content/resources/language/c-sharp/intro.md @@ -0,0 +1,27 @@ +--- +authors: + - "Stone_Red#2890" +created_at: 2021/08/07 +title: C# +--- + +###### Documentation + +- [C# docs](https://docs.microsoft.com/en-us/dotnet/csharp/) + +###### Tutorials + +- [Introduction to C#](https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/intro-to-csharp/) +- [C# Fundamentals Development for Absolute Beginners:](https://channel9.msdn.com/Series/CSharp-Fundamentals-for-Absolute-Beginners) +- [AngelSix's C# Beginner's course](https://www.youtube.com/watch?v=STw363BHviY&list=PLrW43fNmjaQXhWOKalftye87ObZA-xNIJ) + +###### Books + +- [Fundamentals of Computer Programming with C#](https://introprogramming.info/english-intro-csharp-book/) + +###### Others + +- [D#+](https://github.com/DSharpPlus/DSharpPlus/) +- [D#+ Documentation](https://dsharpplus.github.io/) +- [Discord.NET](https://github.com/RogueException/Discord.Net) +- [Discord.NET Documentation](https://docs.stillu.cc/)