You are on page 1of 4

dotnet ?

dotnet --help

dotnet --list-sdks

dotnet new console -n Exercice1.01

dotnet run --project Exercice1.01

Exercice1.01 (.exe) a-t-on besoin du dll? Voir le .deps.json

Et regarder le program.cs …. (Instruction de niveau supérieur)

Declaring Variables

case-sensitive, explicitly(Before a variable is used, it must have a value assigned

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

// Declare without initializing.

string message1;

// Initialize to null.

string message2 = null;

// Initialize as an empty string

string message3 = System.String.Empty;

// Will have the same content as the above one

string message4 = "";

// With implicit declaration

var message4 = "A random message" ;


string interpolation : Console.WriteLine($"Hi {name}, it is very nice to meet you. We have a really fun
journey ahead.");
dotnet new console -n Exercise1_03 //voir l’exercice

dotnet run --project Exercise1_03

Numeric types
sbyte: Holds values from -128 to 127

short: Holds values from -32,768 to 32,767

int: Holds values from -2,147,483,648 to 2,147,483,647

long: Holds values from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

(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:

var myFloat = 10f;

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:

var myDouble = 10d;

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:

var myDecimal = 10m;

The larger the memory space allocated to a variable, the less performant the operations with these
variables are.

Classse (classes act as blueprints)


public class Person
{
public Person() { }
public Person(string name, int age){
Name = name;
Age = age;
}
public string Name { get; set; }
public int Age { get; set; }
public void GetInfo(){
Console.WriteLine($"Name: {Name} – IsChild? {IsChild()}");
}
public bool IsChild(){

return Age < 12;


}

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

À voir using ,try catch, async task

CHAPITRE 2

public class Dog


{}

Dog dog= new Dog();

Constructor: public Dog(){}

Dog speedy //an object and the object is not created, just declared, as follows

Rendu (effacer) Properties

You might also like