C# 0 The Complete Reference



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

MemoryStream

 called 


memstrm

. From 


memstrm

 are created a 



StreamReader

 called 


memrdr

 and a 


StreamWriter

 called 


memwtr

. Using 


memwtr

, output 

is written to the memory-based stream. Notice that after the output has been written, 

Flush( )

is called on 



memwtr

. This is necessary to ensure that the contents of 



memwtr

’s buffer are 

actually written to the underlying array. Next, the contents of the underlying byte array are 

displayed manually, using a 



foreach

 loop. Then, using 



Seek( )

, the file pointer is reset to the 

start of the stream, and the memory stream is read using 

memrdr

.

Memory-based streams are quite useful in programming. For example, you can construct 



complicated output in advance, storing it in the array until it is needed. This technique is 

especially useful when programming for a GUI environment, such as Windows. You can 

also redirect a standard stream to read from an array. This might be useful for feeding test 

information into a program, for example.



StringReader_and_StringWriter'>Using StringReader and StringWriter

For some applications, it might be easier to use a 



string

 rather than a 



byte

 array for the 

underlying storage when performing memory-based I/O operations. When this is the case, 

use


StringReader

 and 


StringWriter

.

StringReader

 inherits 

TextReader

, and 


StringWriter

inherits


TextWriter

. Thus, these streams have access to methods defined by those two 

classes. For example, you can call 

ReadLine( )

 on a 


StringReader

 and 


WriteLine( )

 on a 


StringWriter

.

The constructor for 



StringReader

 is shown here:

StringReader(string

str

)

www.freepdf-books.com




Download 4,07 Mb.

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