2
C# : if, switch..case, goto.
1. Microsoft Visual Studio (. 2.5).
2. , ( switch..case, : " ", "" ).
:
;
;
;
.
.
1. (. 2.8).
2. Microsoft Visual Studio (. 2.5).
3. Microsoft Visual Studio (. 2.5, 2.6, 2.7).
4. (. 2.5). , .
5. (. 2.10).
6. (. . 1.10)
Microsoft Visual Studio
, 1 (. 1.5, 1.7, 1.8).
, , , , .
, , .
.
Microsoft Visual Studio , .
, - (Debug/Trace Into) F10. Main ( 2.1). . F10 . . . F10 .
2.1
. Console.ReadLine() .
|
|
Watch ( ).
. -.
. , , . . - 2.3
2.3
. , .
, . . F5 F10.
.
2.6.1. IF
C# if case. .
if () ( , ).
:
If ()
;
Else
;
if . , . . , true (), < >, then, < >, else. , false (), , if.
, .
. :
if (a>b) , ;
if (a>0 && b>0 && c>0) , .
( ) . .
, {}.
:
if (x>y)
{
max=x;
Console.Write("max=", max);
}
else
x=x+1;
. .
:
if (x>y)
{
if (x > z)
max=z;
Console.Write("max=", max);
}
else
x=x+1;
. else if.
1. , 3.
|
|
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.Write(" n = ");
int n = int.Parse(Console.ReadLine());
if(n % 3 == 0)
Console.WriteLine(" {0} 3", n);
else
Console.WriteLine(" {0} 3", n);
Console.Write("Press any key to continue... ");
Console.ReadKey(true);
}
}
}
2.6.2. SWITCH.. CASE
, if . , if. . ( , !), if . switch.
switch .
:
# :
Switch()
{
case 1: 1; break;
case 2: 2; break;
...................................
case N: N; break;
default: