C# 0 The Complete Reference



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

A Second Simple Program

Perhaps no other construct is as important to a programming language as the variable. A 



variable

 is a named memory location that can be assigned a value. It is called a variable 

because its value can be changed during the execution of a program. In other words, the 

content of a variable is changeable, not fixed.

The following program creates two variables called 

x

 and 


y

.

// This program demonstrates variables.



using System;

class Example2 {

  static void Main() {

    int x; // this declares a variable

    int y; // this declares another variable

    x = 100; // this assigns 100 to x

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

    y = x / 2;

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

    Console.WriteLine(y);

  }

}

When you run this program, you will see the following output:



x contains 100

y contains x / 2: 50

This program introduces several new concepts. First, the statement

int x; // this declares a variable

declares a variable called 

x

 of type integer. In C#, all variables must be declared before they 

are used. Further, the kind of values that the variable can hold must also be specified. This 

is called the 



type

 of the variable. In this case, 



x

 can hold integer values. These are whole 

www.freepdf-books.com



24

 

P a r t   I :  



T h e   C #   L a n g u a g e

numbers. In C#, to declare a variable to be of type integer, precede its name with the 

keyword 


Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   68   69   70   71   72   73   74   75   ...   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