using
System;
02
System.Collections.Generic;
03
System.Linq;
04
System.IO;
05
06
//Class Libary IO has been added to the list
07
08
class
Program
09
{
10
11
public
static
void
Main()
12
13
//FileStream file = new FileStream(@"c:\CSharp\CW1_2012.txt", FileMode.Open);
14
// StreamReader read = new StreamReader(file);
15
// The file will be located and and opened for use further into the program.
16
17
Dictionary<
string
, List<
int
>> variableList =
new
>>();
18
whiteSpace =
(File.ReadAllText(
@"c:\CSharp\CW1_2012.txt"
).Where(dataFile => !
char
.IsWhiteSpace(dataFile)).ToArray());
19
// This strips the file of white space.
20
21
[] fields = whiteSpace.Split(
[] {
':'
}, StringSplitOptions.None);
22
// This splits the file up into peices using the semi colon as the point to seperate each char.
23
24
List<
> numbers =
>();
25
// This creates a new list.
26
27
// Action parse = delegate { };
28
29
// Action flush = delegate
30
// {
31
// parse();
32
// numbers.Clear();
33
// };
34
35
foreach
(
field
in
fields
36
// This looks through all of the fields.
37
38
if
.IsDigit(field.FirstOrDefault()))
39
40
numbers.Add(Convert.ToInt32(field));
41
}
42
else
43
44
> currentlist =
null
;
45
46
(!variableList.TryGetValue(field,
out
currentlist))
47
48
currentlist =
49
variableList.Add(field, currentlist);
50
51
52
53
currentlist.AddRange(numbers);
54
55
(var pair
variableList)
56
57
Console.WriteLine(
"{0} {1}"
, pair.Key, pair.Value.Average());
58
Console.ReadLine();
59
60
61
62
63
64
65
66