.


:




:

































 

 

 

 


-




 

- (bool), true false. : .

- :

! Ż .
static void Main(string[] args)
{
bool a, b = true, c = false;
a =!b; // a = false
a =!c; // a = true
}

|| - Ȼ false , false, true;
static void Main(string[] args)
{
bool a, bTrue = true, bFalse = false;
a = bFalse || bFalse; // a = false
a = bFalse || bTrue; // a = true
a = bTrue || bFalse; // a = true
a = bTrue || bTrue; // a = true
}

&& - Ȼ true , true, false;
static void Main(string[] args)
{
bool a, bTrue = true, bFalse = false;
a = bFalse && bFalse; // a = false
a = bFalse && bTrue; // a = false
a = bTrue && bFalse; // a = false
a = bTrue && bTrue; // a = true
}

:

 

>
<
>=
<=
==
!=

 

static void Main(string[] args)
{
bool a;
int b = 2, c = 3, d = 2;
a = b > c; // a = false
a = b < c; // a = true
a = b >= c; // a = false
a = b >= d; // a = true
a = b == c; // a = false
a = b == d; // a = true
a = b!= c; // a = true
}

, .

. .

- : if-else, switch ?: - .

if-else

 

:
if ([ ])
{
, , [ ] = true ()
}
else
{
, , [ ] = false ()
}

 

else .

if-else , :

 

static void Main(string[] args)
{
int a;
Console.WriteLine(" :");
a = Convert.ToInt32(Console.ReadLine()); // *
if (a % 2 == 0) // 2
{
Console.WriteLine(" " + a + " - ");
}
else
{
Console.WriteLine(" " + a + " - ");
}
Console.ReadKey();
}


* Console.ReadLine() . , , . Convert.ToInt32().

if else , :
if ([ ])
[1] // 1
[2]// 2

if :
if ([ 1])
{1}
else if ([ 2])
{2}
else
{3}

 

, , :
static void Main(string[] args)
{
int a, b;
Console.WriteLine(" :");
a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(" :");
b = Convert.ToInt32(Console.ReadLine());
if (a > b)
Console.WriteLine(" ");
else if (a < b)
Console.WriteLine(" ");
else
Console.WriteLine(" ");

Console.ReadKey();
}

 

. !, || &&.

, , :

 

static void Main(string[] args)
{
int t;
Console.WriteLine(" ");
t = Convert.ToInt32(Console.ReadLine());
if (t < -20 || t > 40) // -20 40
Console.WriteLine(" !");
else
Console.WriteLine(" ");
Console.ReadKey();
}

switch

 

switch if-else. :

switch ()
{
case 1:
1;
break;
case 2:
2;
break;
...
case N:
N;
break;
default:
N+1;
break;
}

 

. break switch . , default.

switch, :

 

static void Main(string[] args)
{
int a;
Console.WriteLine(" :");
a = Convert.ToInt32(Console.ReadLine());
switch (a)
{
case 1:
Console.WriteLine("");
break;
case 2:
Console.WriteLine("");
break;
case 3:
Console.WriteLine("");
break;
case 4:
Console.WriteLine("");
break;
case 5:
Console.WriteLine("");
break;
case 6:
Console.WriteLine("");
break;
case 7:
Console.WriteLine("");
break;
default:
Console.WriteLine("");
break;
}
Console.ReadKey();
}

?:

 

. if-else. :

? 1: 2

 

. , 1, - 2.

?: :

 

static void Main(string[] args)
{
int a;
Console.WriteLine(" :");
a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(a % 2 == 0? " ": " ");
Console.ReadKey();
}

 

?: . , :

 

static void Main(string[] args)
{
int a, b, max;
Console.WriteLine(" :");
a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(" :");
b = Convert.ToInt32(Console.ReadLine());
max = a > b? a: b;
}

, . () . , ( ). . .

- .

 

- , . :

 

- :

[] _ = new [ ];

 

:
int[] array = new int[5]; //
string[] seasons = new string[4] {"","","",""}; //

, new :

 

string[] seasons = {"","","",""}; //

. , 0, n-1, n .

 

static void Main(string[] args)
{
int[] numbers = new int[5];
numbers[0] = 5;
numbers[1] = 2;
numbers[4] = 3;
numbers[5] = 2; // ,
}

, , (), .

 

(). .

 

, .

 

int[,] numbers1 = new int[2, 2]; //
int[,,] numbers2 = new int[2, 2,3]; //
int[,] numbers3 = new int[3, 2] { {6, 0},
{5, 7},
{8, 9} }; //

numbers1 1,1 8:
numbers1[1, 1] = 8;

.

 





:


: 2017-03-11; !; : 2005 |


:

:

. .
==> ...

1292 - | 1255 -


© 2015-2024 lektsii.org - -

: 0.016 .