vimwiki/tech/C-sharp.wiki

156 lines
2.5 KiB
Plaintext
Raw Normal View History

2021-09-22 17:23:25 +00:00
= C# =
Purely object oriented language that relies on a JIT. Primary library is .NET
2022-02-22 20:00:01 +00:00
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 ==
2022-02-22 20:15:01 +00:00
* 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`.
2022-02-22 20:30:01 +00:00
== [[interface]] ==
2022-02-22 20:15:01 +00:00
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");
}
}
}}}
2022-02-22 20:30:01 +00:00
See [[interface]]
2022-02-22 20:00:01 +00:00
== Examples ==
=== Hello World ===
{{{
class Application
{
public static void Main(string[] args)
{
Console.WriteLine("Hello world!");
}
}
}}}
== ASP.NET ==
2022-02-23 19:45:01 +00:00
See [[asp.net.wiki|ASP.NET]]
2021-09-22 17:23:25 +00:00
2022-02-24 19:15:01 +00:00
== .NET ==
see [[dotnet]]
2021-09-22 17:23:25 +00:00
2021-09-24 04:22:57 +00:00
[[index]]