Language
Class name and function name seems to have Capitalize letter in front
Instructions
Instruction end with a ;
# can be name or name.subname.subname # follow the directory tree namespace name { } # inside namespace class name { } interface name<out type> { }
Function call is the function name followed by (), parameter are comma separated in the ().
Function declaration: visibility [static] returntype Name(arg1, arg2) {}
Function declaration: visibility [static] returntype Name(arg1, arg2) => ReturnInstruction;
Constructor: function name with the same name that the class
Property declaration: visibility [readonly] variableType variableName;
public string bla { get; set; }
Visibility: public|private
[Annotation(Property = bla, ...)] just before a class
Template: VarType<SomeType>
Variables
Declaration: type name = value
Types
char with single quote: 'a'
string with double quote: "bla" # string are object, and you can use method on them
Operator
object.property object.property?.maybenull nullish ?? othervar string Concatenation: a + b string Interpolation: $"Test {variable}"
String Methods
# on an object string string.Contains(string) : bool string.Replace(string a, string b) : string string.ToLower() : string string.ToUpper() : string string.Trim() : string string.TrimEnd() : string string.TrimStart() : string string.StartsWith() : bool string.EndsWith() : bool # static call on string string.IsNullOrEmpty(string a): bool
Conversion
bool true : "True"
bool false : "False"
Library
Console.WriteLine(string) DateTime.Now: string
Hello World
In the csharp console:
Console.WriteLine("Hello World!");
CLI App
using System; namespace myApp { class Program { static void Main(string[] args) { Console.WriteLine("Hello World!"); } } }
Programs
Compile a program file to program.exe with C Sharp Compiler (csc)
csc program.cs
dotnet sdk (debian 10)
wget https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb -O packages-microsoft-prod.deb sudo dpkg -i packages-microsoft-prod.deb sudo apt update # 91.6 Mo sudo apt install dotnet-sdk-5.0 # checking dotnet # create a folder "myWebApp" with a configuration in "myWebApp.csproj" dotnet new webApp -o myWebApp --no-https cd myWebApp dotnet run # open http://localhost:5000/ in a browser
Hyperliens...
- Tutorial Hello World from Microsoft (string)
- Hello Wolrd (program)
Dernière modification: 2020-12-31 04:33:50 par Yan Morin
Hébergé par ProgYSM