Write a program in C# Sharp to create and read the last line of a file
- برمجة سي شارب
- برمجة
- 2021-06-01
- ahmadghneem
الأجوبة
using System;
using System.IO;
class filexercise12
{
static void Main()
{
string fileName = @"mytest.txt";
string[] ArrLines ;
int n,i;
Console.Write("\n\n Create and read the last line of a file :\n");
Console.Write("-----------------------------------------------\n");
if (File.Exists(fileName))
{
File.Delete(fileName);
}
Console.Write(" Input number of lines to write in the file :");
n= Convert.ToInt32(Console.ReadLine());
ArrLines=new string[n];
Console.Write(" Input {0} strings below :\n",n);
for(i=0;i<n;i++)
{
Console.Write(" Input line {0} : ",i+1);
ArrLines[i] = Console.ReadLine();
}
System.IO.File.WriteAllLines(fileName, ArrLines);
Console.Write("\n The content of the last line of the file {0} is :\n",fileName);
if (File.Exists(fileName))
{
string[] lines = File.ReadAllLines(fileName);
Console.WriteLine(" {0}",lines[n-1]);
}
Console.WriteLine();
}
}
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال