tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
|
|
@ -0,0 +1,44 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace GetLine
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine(GetLine(args[0], uint.Parse(args[1])));
|
||||
}
|
||||
|
||||
private static string GetLine(string path, uint line)
|
||||
{
|
||||
using (var reader = new StreamReader(path))
|
||||
{
|
||||
try
|
||||
{
|
||||
for (uint i = 0; i <= line; i++)
|
||||
{
|
||||
if (reader.EndOfStream)
|
||||
return string.Format("There {1} less than {0} line{2} in the file.", line,
|
||||
((line == 1) ? "is" : "are"), ((line == 1) ? "" : "s"));
|
||||
|
||||
if (i == line)
|
||||
return reader.ReadLine();
|
||||
|
||||
reader.ReadLine();
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
return ex.Message;
|
||||
}
|
||||
catch (OutOfMemoryException ex)
|
||||
{
|
||||
return ex.Message;
|
||||
}
|
||||
}
|
||||
|
||||
throw new Exception("Something bad happened.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue