.NET is an open-source developer platform from Microsoft for building all sorts of applications.
dotnet
.assembly Hello {}
.assembly extern mscorlib {}
.method static void Main()
{
.entrypoint
.maxstack 1
ldstr "Hello, world!"
call void [mscorlib]System.Console::WriteLine(string)
ret
}
.csproj - Defines a C# project .sln - Organizes multiple projects (monorepo).cs - C# source fileobj - Object, or intermediate, filesbin - Binary files
.exe) or library assemblies (.dll)
using System;
namespace MyNamespace;
class Program {
static void Main(string[] args) {
string message = "Hello, world!"
// var message = "Hello, world!"
Console.WriteLine(message);
}
}
static void Main(string[] args) {
if (myInt > 10) {
// do something
} else {
// do something else
}
foreach (var item in myList) {
// do something with item
}
try {
// some code that might throw an exception
} catch (Exception ex) {
// handle the exception
}
}
class Person
{
private int age;
public int Age {
get { return age; }
set { age = value; }
}
public string FirstName { get; set; }
public string LastName { get; set; }
public string FullName => $"{FirstName} {LastName}";
}
public class Animal {
public virtual void MakeSound() {
Console.WriteLine("The animal makes a sound");
}
}
public class Cat : Animal {
public override void MakeSound() {
Console.WriteLine("The cat meows");
}
}
[Serializable]
public class MyClass {
[Obsolete("This method is deprecated.")]
public void MyOldMethod() {
// do something old
}
}
public class MyGenericClass<T> {
private T[] myArray;
public MyGenericClass(int size) {
myArray = new T[size];
}
public void SetItem(int index, T item) {
myArray[index] = item;
}
public T GetItem(int index) {
return myArray[index];
}
}