kota's memex

The data types in c# such as string and int are actually classes in the .NET library. The language masks the connection between these data types and their c# classes, but behind the scenes they're implemented just like every other class in c#. This means variables like strings and ints have helpful built-in methods for things like converting to uppercase (ToUpper) and so on.

Type Inference (var)

The var keywork instructs the compiler to infer the type.

var message = "Hello World";

Type Casting and Conversion

Type conversions are done with the Convert class.

int x = (int)3.3;

string one = "1";
int firstNumber = Convert.ToInt32(one);

string

It is important to remember that string is a reference type, but it is immutable. That means once it has been assigned a value, it can't be altered. In C#, when methods and operators are used to modify a string, the result that is returned is actually a new string object.

Default type

A string's default type is null rather than an empty string.

Length

Property representing the length of a string.

Trim()

Removes spacing from ends of string.

ToLower()

Converts a string to lowercase.

Split()

string[] address = ipv4Input.Split(".");

int

Integral Types

sbyte and byte

short and ushort

int and uint

long and ulong

MaxValue and MinValue

Properties representing the min and max values for the type.

decimal

Floating point types

float ~6-9 digits of precision

double ~15-17 digits of precision

decimal ~28-29 digits of precision

bool