File 1. satr berilgan. Agar ruxsat etilgan fayl nomi bo’lsa, shunday nomli bo’sh fayl hosil qilinsin va true chiqarilsin. Agar nomli fayl hosil qilish mumkin bo’lmasa false chiqarilsin.
Dasturning C# dagi ko’rinishi: using System;
using System.IO;
namespace File_1
{
class Program
{
publicstatic void Main(string[] args)
{
try {
string S;
Console.Write("Yaratiladigan fayl nomini kiriting: ");
S=Console.ReadLine();
File.Create(@"d:\"+S);
Console.WriteLine("True");
}
catch (Exception exc)
{
Console.WriteLine("False");
}
Console.ReadKey(true);
}
}
}
Natija: File 2. Fayl nomi va natural son berilgan. Berilgan nomli fayl yaratilsin va unga dastlabki ta juft natural sonlarni yozilsin .
Dasturning C# dagi ko’rinishi: using System;
using System.IO;
namespace File_2
{
class Program
{
public static void Main(string[] args)
{
string s; int n;
Console.Write("Yaratiladigan fayl nomini kiriting: ");
s=Console.ReadLine();
Console.Write("Natural son kiriting: n=");
n=int.Parse(Console.ReadLine());
string a="";
for (int i=0;iToString()+" ";
File.WriteAllText(@"d:\"+s+".txt",a);
// FileInfo a=new FileInfo (@"d:\"+s);
// StreamWriter b=a.AppendText();
// for (int i=0;i// b.Close();
// StreamWriter a=new StreamWriter(@"d:\"+s);
// for (int i=0;iConsole.Natija:__File_4.'>Natija:_File_3.'>ReadKey(true);
}
}
}
Natija: File 3. Fayl nomi, va haqiqiy sonlar berilgan. berilgan nomli fayl hosil qilinsin va unga arifmetik progressiyaning dastlabki 10 ta hadini yozilsin. arifmetik progressiya birinchi hadi, arifmetik progressiyaning ayirmasi.
Dasturning C# dagi ko’rinishi: using System;
using System.IO;
namespace File_3
{
class Program
{
public static void Main(string[] args)
{
string s; double A,D;
Console.Write("Yaratiladigan fayl nomini kiriting: ");
s=Console.ReadLine();
Console.Write("Haqiqiy son kiriting: A=");
A=double.Parse(Console.ReadLine());
Console.Write("Haqiqiy son kiriting: D=");
D=double.Parse(Console.ReadLine());
StreamWriter a=new StreamWriter(@"d:\"+s);
for (int i=0;i<10;i++) a.Write((A+D*i)+" "); a.Close();
Console.ReadKey(true);
}
}
}
Natija:
File 4. 4 ta fayl nomi berilgan. Shu katalogda joylashgan, ko’rsatilgan nomli fayllarning mavjudlari sonini topish dasturi tuzilsin.
Dasturning C# dagi ko’rinishi: using System;
using System.IO;
namespace File_4
{
class Program
{
public static void Main(string[] args)
{
string s; int n=0;
for (int i=1;i<=4;i++)
{
Console.Write(i+"-fayl nomini kiriting: ");
s=Console.ReadLine();
FileInfo a=new FileInfo(@"d:\"+s);
if (a.Exists) n++;
}
Console.WriteLine(n);
Console.ReadKey(true);
}
}
}
Natija:
File 5. Butun sonlar fayli nomi berilgan. Berilgan fayldagi elementlar sonini topish dasturi tuzilsin. Agar berilgan nomli fayl joriy katalogda bo’lmasa, -1 chiqarilsin.