C# 0 The Complete Reference


int . Thus, the preceding statement declares a variable called  x



Download 4,07 Mb.
Pdf ko'rish
bet73/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   69   70   71   72   73   74   75   76   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

int

. Thus, the preceding statement declares a variable called 



x

 of type 



int

.

The next line declares a second variable called 



y

.

int y; // this declares another variable



Notice that it uses the same format as the first except that the name of the variable is 

different.

In general, to declare a variable, you will use a statement like this:

type var-name

;

Here, 



type

 specifies the type of variable being declared, and 



var-name

is the name of the 

variable. In addition to 

int

, C# supports several other data types.

The following line of code assigns 

x

 the value 



100

:

x = 100; // this assigns 100 to x



In C#, the assignment operator is the single equal sign. It copies the value on its right side 

into the variable on its left.

The next line of code outputs the value of 

x

 preceded by the string “x contains ”.

Console.WriteLine("x contains " + x);

In this statement, the plus sign causes the value of 



x

 to be displayed after the string that 

precedes it. This approach can be generalized. Using the 

+

 operator, you can chain together 

as many items as you want within a single 

WriteLine

(

 )

 statement.

The next line of code assigns 



y

the value of 



x

 divided by 



2

:

y = x / 2;



This line divides the value in 

x

 by 


2

 and then stores that result in 



y

. Thus, after the line 

executes,

y

 will contain the value 50. The value of 



x

 will be unchanged. Like most other 

computer languages, C# supports a full range of arithmetic operators, including those 

shown here:

+

Addition


Subtraction

*

Multiplication



/

Division


Here are the next two lines in the program:

Console.Write("y contains x / 2: ");

Console.WriteLine(y);

Two new things are occurring here. First, the built-in method 



Write( )

 is used to display the 

string “y contains x / 2: ”. This string is 

not

 followed by a new line. This means that when 

the next output is generated, it will start on the same line. The 

Write( )

 method is just like 



WriteLine( )

, except that it does not output a new line after each call. Second, in the call 

www.freepdf-books.com



Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   69   70   71   72   73   74   75   76   ...   1096




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish