pause at 31minutes
This commit is contained in:
84
C# Full Course for free/3.Variables.md
Normal file
84
C# Full Course for free/3.Variables.md
Normal file
@@ -0,0 +1,84 @@
|
||||
# Variables
|
||||
|
||||
## int
|
||||
|
||||
for storing integer
|
||||
|
||||
```c#
|
||||
int age = 21;
|
||||
```
|
||||
|
||||
## double
|
||||
|
||||
can store a decimal
|
||||
|
||||
```C#
|
||||
double height = 300.5;
|
||||
```
|
||||
|
||||
## bool
|
||||
|
||||
can store boolean
|
||||
only true or false
|
||||
|
||||
```C#
|
||||
bool alive = true;
|
||||
```
|
||||
|
||||
## char
|
||||
|
||||
for a single carachter
|
||||
|
||||
```C#
|
||||
char symbole = '@';
|
||||
```
|
||||
|
||||
## String
|
||||
|
||||
don't forget the S in upper
|
||||
|
||||
```C#
|
||||
String name = "Hello";
|
||||
```
|
||||
|
||||
## constants
|
||||
|
||||
immutable values wich are known at compile time and
|
||||
do not change for th life of the program
|
||||
|
||||
just add the const keyword
|
||||
|
||||
```C#
|
||||
const double pi = 3.14;
|
||||
```
|
||||
|
||||
## Type casting
|
||||
|
||||
Converting a value to a different data type
|
||||
Very useful because user input will always be strings
|
||||
|
||||
```C#
|
||||
double a = 3.14;
|
||||
int b= Convert.ToInt32(a);
|
||||
|
||||
int c= 123;
|
||||
double d= Convert.ToDouble(c);
|
||||
|
||||
int e= 321;
|
||||
String d= Convert.ToString(e);
|
||||
|
||||
String g = "$";
|
||||
char h = Convert.ToChar(g);
|
||||
|
||||
String i = "true";
|
||||
bool j = Convert.ToBoolean(i);
|
||||
```
|
||||
|
||||
## GetType
|
||||
|
||||
Get the type of a variable
|
||||
|
||||
```C#
|
||||
double a = 3.14;
|
||||
Console.WriteLine(a.GetType())
|
||||
```
|
||||
Reference in New Issue
Block a user