Formation C#

 

Level One

Animée par

Mohamed IDBRAHIM

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Section 1

C# vs .NET

CLR (Common Language Run-time)

Architecture of .NET Applications

Our first C# Application

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

C# vs .NET

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

C# vs .NET

C# is a programming language 

.NET is a framework for building applications on windows

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

.NET

CLR (Common Language Run-time) 

Class library

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Architecture of .NET applications

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Architecture of .NET applications

Class

Class

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Architecture of .NET applications

Class

Class

Class

Class

Class

Class

Namespace

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Architecture of .NET applications

Assembly   DLL / EXE

Namespace 1

Namespace 2

Namespace 3

Namespace 4

Namespace 5

Namespace n

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Architecture of .NET applications

Application

Assembly 1

Assembly 2

Assembly 3

Assembly 4

Assembly 5

Assembly n

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Télécharger

Visual Studio 2017

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Variables and Constants

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Variables and Constants

  • Variable: a name given to storage location in memory.

  • Constant : an immutable value  Pi = 3.14

 

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

1 - Declaring Variables/Constants


   int number;
   
   int Number = 1;

   const float Pi = 3.14f;

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

1 - Cannot start with a number

1route

oneRoute

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

2 - Cannot include a whitespace

first name

firstName

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

3 - Cannot be a reserved keyword

int

@int

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

4 - Use meaningful names

fn

firstName

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Naming Conventions

  • Camel case: firstName

  • Pascal case: FirstName

  • Hungarian notation: strFirstName

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Naming Conventions

- for local variables: Camel case.

int number;

 

- for constant: Pascal case 

const int MaxNumber = 100;

 

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Primitives types

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Real types


   float number = 1.2f;

   decimal number = 1.2m;

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Overflowing


   byte number = 255;

   number = number + 1;

 

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Overflowing


   checked 
   {

     byte number = 255;

     number = number + 1;

   }

 

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Type conversion

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Type conversion

  • Implicit type conversion

  • Explicit type conversion (casting)

  • Conversion between non-compatible types

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Implicit type conversion

    
   byte a = 3;

    int b = a;

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Implicit type conversion


   byte a = 3;                                 00000011

    int b = a;      00000000 00000000 00000000 00000011

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Implicit type conversion


     int a = 21;    

   float b = a;      

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Explicit type conversion

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Explicit type conversion


    int a = 2;

    byte b = a;    // won't compile

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Explicit type conversion


    int a = 2;

    byte b = (byte)a;

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Explicit type conversion


    float a = 2.5f;

    int b = (int)f;

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Non compatible Types

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Non compatible Types


   string i = "123";

      int j = (int)i;  //won't compile

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Non compatible Types


   string i = "123";

      int j = Convert.ToInt32(i);

      int k = int.Parse(i);

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Operators

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Operators

  • Arithmetic Operators

  • Comparaison Operators

  • Assignment Operators

  • Logical Operators

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Operators

Arithmetic Operators

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Operators

Arithmetic Operators

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Operators

Arithmetic Operators


    int a = 1;

    int b = a++;

Postfix Increment

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Operators

Arithmetic Operators


    int a = 1;

    int b = a++;

Postfix Increment

a = 2   et   b = 1

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Operators

Arithmetic Operators


    int a = 1;

    int b = ++a;

Prefix Increment

a = 2   et   b = 2

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Operators

Comparaison Operators

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Operators

Assignment Operators

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Operators

Logical Operators

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Comments

Mohamed IDBRAHIM

http://eleandev.net

Fondamentaux de C#

Comments

Single Line comment

  
   // Here is a single line comment
   int number = 1;

Multi Line comment

  
   /* 
      Here is a single line 
      comment
   */
   int number = 1;

Formation sur C SHARP - C# - Level 1

By Mohamed IDBRAHIM

Formation sur C SHARP - C# - Level 1

  • 607