C# 0 The Complete Reference



Download 4,07 Mb.
Pdf ko'rish
bet221/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   217   218   219   220   221   222   223   224   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

foreach

 loop is an excellent choice in this application because searching an array involves 

examining each element. Other types of 

foreach

 applications include such things as computing 

an average, finding the minimum or maximum of a set, looking for duplicates, and so on. 

As you will see later in this book, 



foreach

 is especially useful when operating on other types 

of collections.

Strings

From a day-to-day programming standpoint, one of the most important of C#’s data types is 



string

.

string

 defines and supports character strings. In many other programming languages

a string is an array of characters. This is not the case with C#. In C#, strings are objects. Thus, 



string

 is a reference type. Although 



string

 is a built-in data type in C#, a discussion of 



string

needed to wait until classes and objects had been introduced.

Actually, you have been using the 

string

 class since Chapter 2, but you did not know it. 

When you create a string literal, you are actually creating a 

string

 object. For example, in the 

statement

Console.WriteLine("In C#, strings are objects.");

the string “In C#, strings are objects.” is automatically made into a 

string

 object by C#. Thus, 

the use of the 

string

 class has been “below the surface” in the preceding programs. In this 

section, you will learn to handle them explicitly.

Constructing Strings

The easiest way to construct a 



string

 is to use a string literal. For example, here 



str

 is a 


string

 reference variable that is assigned a reference to a string literal:

string str = "C# strings are powerful.";

In this case, 



str

 is initialized to the character sequence “C# strings are powerful.”

You can also create a 

string

 from a 


char

 array. For example:

char[] charray = {'t', 'e', 's', 't'};

string str = new string(charray);

www.freepdf-books.com



Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   217   218   219   220   221   222   223   224   ...   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