-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListFromFileLoader.cs
More file actions
49 lines (44 loc) · 1.15 KB
/
ListFromFileLoader.cs
File metadata and controls
49 lines (44 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
namespace _2_interfejsy_kolekcje
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
public class ListFromFileLoader
{
private string[] stringArray;
public List<string> Load(string path)
{
var stringList = new List<string>();
if (LoadFromFile(path) && stringArray.Any())
{
foreach (string line in stringArray)
{
stringList.Add(line);
}
}
return stringList;
}
private bool LoadFromFile(string path)
{
bool result = true;
try
{
stringArray = File.ReadAllLines(path);
}
catch(ArgumentNullException ex)
{
result = false;
}
catch(FileNotFoundException ex)
{
result = false;
}
catch(PathTooLongException ex)
{
result = false;
}
return result;
}
}
}