mirror of
https://github.com/Stone-Red-Code/website.git
synced 2026-09-06 16:06:12 +02:00
Basic resources added
- intro - naming conventions - access modifiers
This commit is contained in:
@@ -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.
|
||||||
@@ -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
|
||||||
|
{
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -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/)
|
||||||
Reference in New Issue
Block a user