.


:




:

































 

 

 

 


, .




// , using System;

class ScopeDemo {

static void Main() {

int x; // Main().

= 10;

if ( == 10) { //

int = 20; // .

// , .

Console.WriteLine(" : " + + " " + ); = * 2;

}

// = 100; // ! .

// - .

Console.WriteLine(" " + );

}

}

, Main (), . i f . , . line = 1 00;, , . (//), , . i f, , , , .

, . , , . , , , , .

, , . .

// .

Using System;

class VarlnitDemo { static void Main() { int x;

for(x = 0; x < 3; x++) {

int = -1; // . Console.WriteLine(" : " + ); // -1

= 100;

Console.WriteLine(" : " + );

}

}

}

.

 

 

:

 

-1

 

 

 

:

 

 

 

:

 

-1

 

 

 

:

 

 

 

:

 

-1

 

 

 

:

 

 

, -1 for. , 100, .

C# : , , , . , .

/*

, , .

*** . ***

*/

Using System;

class NestVar {

static void Main() { int count;

for(count = 0; count < 10; count = count+1) {

Console.WriteLine(" : " + count);

int count; // !!!

for(count = 0; count < 2; count++)

Console.WriteLine(" !");

}

}

}

C++, , , , . , C++ count , for, , . C++ . C# , , .

. , int float.

Int i; float f;

i = 10;

f = i; // float

, , . i float, f. C# , , . , bool int . , - . , , . , .

, :

;

, .

, . , int , byte, , , int byte, , .

, , , . , , long double .

// long double.

Using System;

class LtoD {

static void Main() { long L; double D;

L = 100123285L;

D = L;

Console.WriteLine("L D: " + L + " " + D);

}

}

long double , double long , . , .

// *** . ***

Using System;

/

class LtoD {

static void Main() { long L; double D;

D = 100123285.0;

L = D; // !!!

Console.WriteLine("L D:&#9632; " + L + " " + D);

}

}

, decimal float double, char bool. , char bool .

, , . . . . .

(_)

_ , . .

Double , ;

/ int, .

(int) ( / )

double, / int . / , int , . , double int .

, . , long int , long int, . , . , 1,23 , (1), (0,23) .

, . , .

// .

Using System;

class CastDemo {

static void Main() { double x, y; byte b; int i; char ch; uint u; short s; long 1;

x = 10.0;

= 3.0;

11 double int, , i = (int) ( / );

Console.WriteLine(" / : " + i); Console.WriteLine();

// int byte , i = 255; b = (byte) i;

Console.WriteLine("b 255: " + b +

" -- .");

// int byte , i = 257; b = (byte) i;

Console.WriteLine("b 257: " + b +

" .");

Console.WriteLine();

// uint short , = 32000; s = (short) u;

Console.WriteLine("s 32000: " + s + " .");

// uint short , = 64000; s = (short) u;

Console.WriteLine("s 64000: " + s + " . ");

Console.WriteLine();

// long uint .

1 = 64000; u = (uint) 1;

Console.WriteLine(" 64000: " + u +

" -- .");

// long uint .

1 = - 12; u = (uint) 1;

Console.WriteLine(" -12: " + u +

" .");

Console.WriteLine();

// int char, b = 88; // ASCII X ch = (char) b;

Console.WriteLine("ch 88: " + ch);

}

}





:


: 2016-12-03; !; : 502 |


:

:

, , 1:10
==> ...

1690 - | 1624 -


© 2015-2024 lektsii.org - -

: 0.025 .