Type | Description |
---|---|
int | whole numbers from -2,147,483,648 to 2,147,483,647 |
long | Stores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
float | Stores fractional numbers. Sufficient for storing 6 to 7 decimal digits |
double | Stores fractional numbers. Sufficient for storing 15 decimal digits |
bool | Stores true or false values |
char | Stores a single character/letter, surrounded by single quotes |
string | Stores a sequence of characters, surrounded by double quotes |
Int wordt meer gebruikt dan long, long value eindigt met L. Float en double values eindig je met een F en D respectively.
Implicit: smaller to larger (char -> int -> long -> float -> double).
int myInt = 9;
double myDouble = myInt; // Automatic casting: int to double
Console.WriteLine(myInt); // Outputs 9
Console.WriteLine(myDouble); // Outputs 9
Explicit: larger to smaller (double -> float -> long -> int -> char).
double myDouble = 9.78;
int myInt = (int) myDouble; // Manual casting: double to int
Console.WriteLine(myDouble); // Outputs 9.78
Console.WriteLine(myInt); // Outputs 9
Andere methodes: Convert.ToBoolean, Convert.ToDouble, Convert.ToString, Convert.ToInt32 (is int) en Convert.ToInt64 (is long). Na de Convert.To[type] komt de variabele in (). Dus Convert.ToString(x).
// Type your username and press enter
Console.WriteLine("Enter username:");
// Create a string variable and get user input from the keyboard and store it in the variable
string userName = Console.ReadLine();
// Print the value of the variable (userName), which will display the input value
Console.WriteLine("Username is: " + userName);
Met conversie:
Console.WriteLine("Enter your age:");
int age = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Your age is: " + age);
Operator | Name | Description | Example |
---|---|---|---|
+ | Addition | Adds together two values | x + y |
- | Subtraction | Subtracts one value from another | x - y |
* | Multiplication | Multiplies two values | x * y |
/ | Division | Divides one value by another | x / y |
% | Modulus | Returns the division remainder | x % y |
++ | Increment | Increases the value of a variable by 1 | x++ |
-- | Decrement | Decreases the value of a variable by 1 | x-- |
Fuck my stupid baka life