Professional Documents
Culture Documents
dotnet --help
dotnet --list-sdks
Declaring Variables
ex: int a=0; ou int a, b = 100, c = 10; ) and implicitly (var name = "Elon Musk")
string (immutable): This happens because strings in C# are an array of characters. Arrays are data
structures that gather objects of the same type and have a fixed length
string message1;
// Initialize to null.
Numeric types
sbyte: Holds values from -128 to 127
(Unsigned: byte,ushort,uint,ulong)
Float: This occupies four bytes and can store numbers from ± 1.5 x 10−45 to ± 3.4 x 1038 with a precision
range of six to nine digits. To declare a float number using var, you can simply append f to the end of the
number, like so:
double: This occupies eight bytes and can store numbers from ± 5.0 × 10−324 to ± 1.7 × 1030 with a
precision range of 15 to 17 digits. To declare a double number using var, you can append d to the end of
the number, like so:
decimal: This occupies 16 bytes and can store numbers from ± 1.0 x 10-28 to ± 7.9228 x 1028 with a
precision range from 28 to 29 digits. To declare a decimal number using var, you must simply append m
to the end of the number, like so:
The larger the memory space allocated to a variable, the less performant the operations with these
variables are.
Dates
DateTime (MinValue(Dafault), which is January 1, 0001 00:00:00, and MaxValue,
which is December 31, 9999 11:59:59)
var now = DateTime.Now;
Bool
If-else
var gift = person.IsChild() ? "Toy" : "Clothes"; (if ternaire)
Reference and Value Types
The built-in value types for C# are bool, byte, char, decimal, double, enum, float, int, long,
sbyte, short, struct, uint, ulong, and ushort.
The three main reference types you need to know about in this chapter are string,
array, and class
When value type variables are passed as parameters or assigned as
the value of another variable, the .NET runtime copies the value
of the variable to the other object. This means that the original
variable is not affected by any changes made in the newer and
subsequent variables, as the values were literally copied from
one place to another.
When reference type variables are passed as parameters or
assigned as the value of another variable, .NET passes the heap
memory address instead of the value. This means that every
subsequent change made in this variable inside a method will be
reflected outside.
Note that since you are using top-level statements, these declarations should be
above the class and the struct declarations
Switch – default The matching expression should return a value that is of one of the following types:
char, string, bool, numbers, enum, and object
While {} break, continue
Do-{}while
ARRAYS int[] numbers={1,2,3,4,5};
var numbers=new int[5];
for (int j=0; j<numbers.Lenght-1; j++){}
foreach (int element in numbers){}
File (FileStream: FileAccess (read, readwrite, write) and Filemode (Append, create,
createNew, Open, OpenOrCreate)), Directory, Path, DriveInfo
CHAPITRE 2
Dog speedy //an object and the object is not created, just declared, as follows