C# 0 The Complete Reference


PART I C h a p t e r   1 4



Download 4,07 Mb.
Pdf ko'rish
bet505/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   501   502   503   504   505   506   507   508   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt


PART I

C h a p t e r   1 4 :  

U s i n g   I / O  

395


PART IPART I

Here, 


str

 is the string that will be read from.



StringWriter

 defines several constructors. Here is the one that we will use:

StringWriter( )

This constructor creates a writer that will put its output into a string. This string (in the form 

of a 

StringBuilder

) is automatically created by 



StringWriter

. You can obtain the contents of 

this string by calling 

ToString( )

.

Here is an example that uses 



StringReader

 and 


StringWriter

:

// Demonstrate StringReader and StringWriter.



using System;

using System.IO;

class StrRdrDemo {

  static void Main() {

    // Create a StringWriter.

    StringWriter strwtr = new StringWriter();

    // Write to StringWriter.

    for(int i=0; i < 10; i++)

      strwtr.WriteLine("This is i: " + i);

    // Create a StringReader.

    StringReader strrdr = new StringReader(strwtr.ToString());

    // Now, read from StringReader.

    string str = strrdr.ReadLine();

    while(str != null) {

      str = strrdr.ReadLine();

      Console.WriteLine(str);

    }

  }


}

The output is shown here:

This is i: 1

This is i: 2

This is i: 3

This is i: 4

This is i: 5

This is i: 6

This is i: 7

This is i: 8

This is i: 9

The program first creates a 




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   501   502   503   504   505   506   507   508   ...   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