Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AnkietaService
- {
- public static List<string> ReadFile()
- {
- String path = HostingEnvironment.MapPath(@"\App_Data\Ankieta.csv");
- IEnumerable<string> strCSV =
- File.ReadLines(path);
- var results = from str in strCSV
- let tmp = str.Split(';')
- .Skip(1)
- .Select(x => Convert.ToInt32(x))
- select new
- {
- Max = tmp.Max(),
- Min = tmp.Min(),
- Total = tmp.Sum(),
- Avg = tmp.Average()
- };
- // caching for performance
- var query = results.ToList();
- List<string> lista = new List<string>();
- foreach (var x in query)
- {
- lista.Add(
- string.Format("Maximum: {0}, " +
- "Minimum: {1}, " +
- "Total: {2}, " +
- "Average: {3}",
- x.Max, x.Min, x.Total, x.Avg));
- }
- return lista;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement