C# dasturlash tilida massivlar bilan ishlash



Yüklə 171,84 Kb.
səhifə22/22
tarix29.11.2023
ölçüsü171,84 Kb.
#139157
1   ...   14   15   16   17   18   19   20   21   22
c dasturlash tilida fayllar bilan ishlash

5- misol. fayldan ma’lumotlarni satrma - satr o’qish.
class Program
{ static void Main(string[] args)
{
FileStream a = new FileStream("d:\\textFile.txt", FileMode.Open,
FileAccess.Read);
StreamReader b = new StreamReader(a);
string s; while ((s = b.ReadLine()) != null){ Console.WriteLine(s); }
b.Close();
Console.ReadKey();
} }
6- misol. a.txt fayldagi barcha sonlarni yig’indisini b.txt faylda chiqarish. class Program
{ static void Main(string[] args)
{
StreamWriter yozish = new StreamWriter("d:\\a.txt"); StreamReader uqish = new StreamReader("d:\\b.txt"); int b, n, k,s=0; string a; while ((a = (uqish.ReadLine())) != null)
{ s = s + int.Parse(a);
} yozish.WriteLine(s+""); yozish.Close();
Console.ReadKey();
} }
7- misol. a.txt fayldagi eng uzun so’zni b.txt faylda chiqarish.
class Program
{ static void Main(string[] args)
{
StreamWriter yozish = new StreamWriter("d:\\a.txt"); StreamReader uqish = new StreamReader("d:\\b.txt"); int b, n, k,s=0; string a,x,y; k:=0; x:= ""; while ((a = (uqish.ReadLine())) != null) {if (a.length()>k) {x = a; k=a.length();}} yozish.WriteLine(x); yozish.Close();
Console.ReadKey();
} }
MUNDARIJA:

C# dasturlash tilida massivlar bilan ishlash 1
Consol rejimi. C# tilining sintaksisi. Ma’lumotlar tiplari. 2
1.2. C# tilida ifoda, instruksiya va operatorlar. 13
FOYDALANGAN ADABIYOTLAR 17
1.3. Sinflar, metodlar, xususiyatlar. 36
II.BOB. C# DASTURLASH TILIDA FAYLLAR BILAN ISHLASH. 47
2.1. Fayl va kataloglar ro’yxati. 47
2.2. Fayl va kataloglar ustida amallar. 55
2.3. Ma’lumotlarni faylda yozish va o’qish. 62



Yüklə 171,84 Kb.

Dostları ilə paylaş:
1   ...   14   15   16   17   18   19   20   21   22




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə