C# 0 The Complete Reference


PART I C h a p t e r   1 4



Download 4,07 Mb.
Pdf ko'rish
bet501/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   497   498   499   500   501   502   503   504   ...   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  

391


PART IPART I

    catch(IOException exc) {

      Console.WriteLine("Cannot Open File");

      Console.WriteLine(exc.Message);

      return ;

    }


    // Write the alphabet.

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

      try {

        f.WriteByte((byte)('A'+i));

      }

      catch(IOException exc) {

        Console.WriteLine("Error Writing File");

        Console.WriteLine(exc.Message);

        f.Close();

        return ;

      }

    }


    try {

      // Now, read back specific values.

      f.Seek(0, SeekOrigin.Begin); // seek to first byte

      ch = (char) f.ReadByte();

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

      f.Seek(1, SeekOrigin.Begin); // seek to second byte

      ch = (char) f.ReadByte();

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

      f.Seek(4, SeekOrigin.Begin); // seek to 5th byte

      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.Seek(i, SeekOrigin.Begin); // seek to ith character

        ch = (char) f.ReadByte();

        Console.Write(ch + " ");

      }

    }


    catch(IOException exc) {

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

      Console.WriteLine(exc.Message);

    }


    Console.WriteLine();

    f.Close();

  }

}

www.freepdf-books.com




392

 

P a r t   I :  



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

The output from the program is shown here:

First value is A

Second value is B

Fifth value is E

Here is every other value:

A C E G I K M O Q S U W Y

Although



Download 4,07 Mb.

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