Getsuyodev, Programming is mainly used when constructing an application. Programming requires knowledge of application domains, algorithms, and programming language expertise. Programming can be developed in different logic based on developer knowledge.

C Sharp – Raccourcis d’assignation

Programmation en C# (C Sharp)



Il est possible d’utiliser les mêmes opérateurs d’assignation (outre  l’affectation simple) présents dans le langage C :

Opérateur d’assignation
équivalent en affectation ordinaire
x += 5
x = x + 5
x -= 5
x = x – 5
x *= 5
x = x * 5
x /= 5
x = x / 5
x %= 5
x = x % 5
x <<= 5
x = x << 5
x >>= 5
x = x >> 5
x &= 5
x = x & 5
x |= 5
x = x | 5
x ^= 5
x = x ^ 5

Exemple : (3 manières d’incrémenter une variable entière)

int x =9;
1°) x = x+1;

2°) x +=1;

3°) x++; ou bien ++x;

using System;

class Exercice
{
public static void Main( ) 
{
string s1, s2="heur", s3="jour" ;

s1="bon";
s1 +=s2;
Console.WriteLine(s1);

s1="bon";
s1 +=s3;
Console.WriteLine(s1);

int x= 5, x0 = x; // 5 =0...0101
x <<=2;  // on décale à gauche de 2 bits soit : 0...010100
Console.WriteLine("avant (x= 5): "+x0 + ", après (x <<=2) : "+x);

Console.ReadLine();
}
}



Comments are closed, but trackbacks and pingbacks are open.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More