Assignment operator (=)
Vazifasi o’ng tomondagi qiymatni chap tomonga o’zlashtirishdan iborat.
Bu operatorni chap tarafida doim o’zgaruvchi turadi.
variable=value|variable|expression
var a = 10; //variable=value
var c = a; //variable=variable
var c=a+b*10; //variable=expression
Compound Assignment Operators
a +=10; //a=a+10;
a -=10; //a=a-10;
a *=10; //a=a*10;
a %=10; //a=a%10;
Increment/Decrement
Faqatgina sonning qiymatini 1 ga oshirish yoki kamaytirish uchun ishlatiladi.
a++;
a--;
Postfix increment/decrement
Avval amalni bajarib,so’ngra qiymatni 1 ga oshirish/kamaytirish.
Agar ++/– expression ichida o’zgaruvchidan keyin kelsa,bu amal boshqa operatsiyalardan keyin bajariladi.
a=0;
var son = a++;
Console.WriteLine(a); // 1
Console.WriteLine(son); // 0
Bu yerda o’zlashtirish amali bajarilib,keyin increment/decrement amali bajariladi.
Prefix increment/decrement
Qiymatni avval 1 ga oshirish/kamaytirish va keyin boshqa amallarni bajarish
a=0;
var son = ++a;
Console.WriteLine(a); // 1
Console.WriteLine(son); //1
var x = 0;
var y = 0;
var z = 0; z = ++x + y++;
Console.WriteLine(x); //1
Console.WriteLine(y); //1
Console.WriteLine(z); //1
Tepadagi dasturga qaraydigan bo’lsak,barcha natijalar 1 chiqqanini guvohi bo’lamiz.Bunda amallar ketma-ketligi quyidagicha bajariladi:
1.Avval x ni qiymati 1 oshiradi
2.Keyin 1 ga y ni qiymati ya’ni 0 ni qo’shadi.
3.So’ngra yig’dini z ga o’zlashtiradi
4.Eng oxirida y ni qiymatini 1 ga oshiradi.
//Chain assignment
O’ngdan chapga qarab amallarni bajaradi.
x = y = z = 15;
Arithmetic Operators (+,-,*,/,%)
Console.WriteLine(10+5);
Console.WriteLine(10-5);
Console.WriteLine(10*5);
Console.WriteLine(10/5);
Console.WriteLine(10%5);
Integer division-butun bo’lish
Butun sonni butun songa bo’lganda,natija ham butun son chiqadi
var son = 10/3; //3
var son1 = 10.3/3 //3.333333
Comparison Operators
1.Qiymatlarni solishtiradi va true/false qiymat qaytaradi
a = 5;
b = 10;
Console.WriteLine(a > b); //false
Console.WriteLine(a >= b); //false
Console.WriteLine(a < b); //true
Console.WriteLine(a <= b); //true
Console.WriteLine(a == b); //false
Console.WriteLine(a != b); //true
Logical Operators
*//Compound *
Bitta belgi o’qing.Agar belgi harf bo’lsa True
yo’qsa False
deb chop eting.
var belgi = (char)Console.Read();
var kichikHarfmi = belgi >= 'a' && belgi < = 'z';
var kattaHarfmi = belgi >= 65 && belgi <=90;
var harfmi = kichikHarfmi || kattaHarfmi; Console.WriteLine(kichikHarfmi);
Console.WriteLine(kattaHarfmi);
Console.WriteLine(harfmi);
Ternary Operator
3 ta qismdan iborat:Condition ? true_value : false_value
Agar condition bararilsa True qiymat qaytaradi,aks holda False qiymat qaytaradi.
var i = int.Parse(Console.ReadLine());
var j = int.Parse(Console.ReadLine()); var kattasi = i > j ? i : j;
Console.WriteLine(kattasi);