C# 0 The Complete Reference


str4  with the string “OneTwoThree”. One other point: The  string



Download 4,07 Mb.
Pdf ko'rish
bet226/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   222   223   224   225   226   227   228   229   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

str4

 with the string “OneTwoThree”.

One other point: The 

string

 keyword is an 



alias

for (that is, maps directly to) the 



System.String

 class defined by the .NET Framework class library. Thus, the fields and 

methods defined by 

string

 are those of the 



System.String

 class, which includes more 

than the sampling described here. 

System.String

 is examined in detail in Part II.

www.freepdf-books.com



160

 

P a r t   I :  



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

Arrays of Strings

Like any other data type, strings can be assembled into arrays. For example:

// Demonstrate string arrays.

using System;

class StringArrays {

  static void Main() {

    string[] str = { "This", "is", "a", "test." };

    Console.WriteLine("Original array: ");

    for(int i=0; i < str.Length; i++)

      Console.Write(str[i] + " ");

    Console.WriteLine("\n");

    // Change a string.

    str[1] = "was";

    str[3] = "test, too!";

    Console.WriteLine("Modified array: ");

    for(int i=0; i < str.Length; i++)

      Console.Write(str[i] + " ");

  }


}

Here is the output from this program:

Original array:

This is a test.

Modified array:

This was a test, too!

Here is a more interesting example. The following program displays an integer value 

using words. For example, the value 19 will display as “one nine”.

// Display the digits of an integer using words.

using System;

class ConvertDigitsToWords {

  static void Main() {

    int num;

    int nextdigit;

    int numdigits;

    int[] n = new int[20];

    string[] digits = { "zero", "one", "two",

                        "three", "four", "five",

                        "six", "seven", "eight",

                        "nine" };

    num = 1908;

www.freepdf-books.com




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   222   223   224   225   226   227   228   229   ...   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