vimwiki/tech/C-sharp.wiki

156 lines
2.5 KiB
Plaintext

= C# =
Purely object oriented language that relies on a JIT. Primary library is .NET
C# is both portable and fast, and coupled with the .NET framework.
== Types ==
* string
* is an object, not a primative data type
* char
* single 16bit unicode char
* byte
* 8 bit unsigned int
* short
* 16 bit signed int
* int
* 32 bit signed int
* long
* 64 bit signed int
* float (2.5F)
* 32bit floating point
* double (3.5)
* 64bit double floating point
* decimal (4.5M)
* 128bit precise decimal
* bool
* 1 bit true false
== Modifiers ==
* const
* not modifiable at runtime
== casting ==
casting works the same way as C/C++
* (int)3.14
Or call convert
* Convert.ToInt32("50");
* Convert.ToDouble("50.0");
== strings ==
* indexing starts at zero
* mystring.length
* mystring[0]
* haystack.IndexOf("Needle")
* haystack.IndexOf("N")
* haystack.Substring(2)
* haystack.Substring(1,3)
== operators ==
* normal + - * /
* Order of operations is preserved
* Modulous is %
* Operations on ints give ints
* += -= *= /= all work
* ++ and -- work
* Math.Pow(base, power)
* Math.Sqrt(144) = 12
* Math.Round(2.7) = 3
== ArrayList ==
* in System.Collections
{{{
ArrayList friends = new ArrayList();
friends.Add("Bob");
friends.Add("Mike");
}}}
== Exceptions ==
{{{
try {
int division = 10 / Convert.ToInt32(Console.ReadLine());
} catch(DivideByZeroException e) {
Console.WriteLine(e);
} catch(Exception e){
Console.WriteLine($"Unkown Error: {e}");
}
}}}
{{{
throw new DivideByZeroException("Cant add that... My Custom error is here");
}}}
== Constructors ==
Called at creation of class, same as C/C++ constructors.
this.xyz is also valid.
== Abstraction ==
declare a class as `abstract`.
To override a class add the modifier `override`.
== [[interface]] ==
An interface is a fully abstract class that can be inherited by other classes.
It provides some set functions to be implimented by the child class.
{{{
public interface Animal{
void Speak();
}
public class Dog : Animal {
public void Speak(){
Console.WriteLine("Woof Woof");
}
}
public class Cat : Animal {
public void Speak(){
Console.WriteLine("Meow");
}
}
}}}
See [[interface]]
== Examples ==
=== Hello World ===
{{{
class Application
{
public static void Main(string[] args)
{
Console.WriteLine("Hello world!");
}
}
}}}
== ASP.NET ==
See [[asp.net.wiki|ASP.NET]]
== .NET ==
see [[dotnet]]
[[index]]