C# 0 The Complete Reference


Seek( )  offers the greatest flexibility, there is another way to set the current file  position. You can use the  Position



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

Seek( )

 offers the greatest flexibility, there is another way to set the current file 

position. You can use the 

Position

 property. As shown previously in Table 14-2, 



Position

 is 


a read/write property. Therefore, you can use it to obtain the current position or to set the 

current position. For example, here is the code sequence from the preceding program that 

reads the “random.dat” file, rewritten to use the 

Position

 property:

// Use Position rather than Seek() to set the current

// file position.

try {

  f.Position = 0;



  ch = (char) f.ReadByte();

  Console.WriteLine("First value is " + ch);

  f.Position = 1;

  ch = (char) f.ReadByte();

  Console.WriteLine("Second value is " + ch);

  f.Position = 4;

  ch = (char) f.ReadByte();

  Console.WriteLine("Fifth value is " + ch);

  Console.WriteLine();

  // Now, read every other value.

  Console.WriteLine("Here is every other value: ");

  for(int i=0; i < 26; i += 2) {

    f.Position = i; // seek to ith character

    ch = (char) f.ReadByte();

    Console.Write(ch + " ");

  }


}

catch(IOException exc) {

  Console.WriteLine("Error Reading or Seeking");

  Console.WriteLine(exc.Message);

}


Download 4,07 Mb.

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