Tutaj trochę bardziej "na piechotę"
namespace ConsoleSimpleDatabaseApplication1
{
using System;
using System.Collections.Generic;
using System.Linq;
public static class Program
{
private static List<Record> records = new List<Record>();
public static void Main(string[] args)
{
var lines = new List<string>
{
"id;login;numer;imie nazwisko;mail",
"1;Admin;123124;Jan Kowalski;jk@a.pl",
"2;AD;133333;Adam Dworak;ad@a.pl",
"3;AR;343434;Antoni Ryczak;ar@a.pl",
"10000;ZZ;4343434;Zenzon Zygiel;zz@a.pl;"
}; // tutaj mozesz zaczytac zawartosc pliku
foreach (var line in lines)
{
Record record;
if (Record.TryParse(line, out record))
{
records.Add(record);
}
}
//tutaj wypluwam calosc do na ekran ale mozna pisac do pliku
Console.WriteLine(Record.Header);
foreach (var record in (from r in records orderby r.Mail select r))
{
Console.WriteLine(record);
}
Console.ReadKey();
}
}
public class Record : IComparable<Record>, IEquatable<Record>
{
public int Id { get; set; }
public string Login { get; set; }
public int Number { get; set; }
public string Name { get; set; }
public string Mail { get; set; }
public static string Header
{
get
{
return "id;login;numer;imie nazwisko;mail";
}
}
public static bool TryParse(string line, out Record record)
{
try
{
var array = line.Split(';');
var id = int.Parse(array[0]);
var login = array[1];
var number = int.Parse(array[2]);
var name = array[3];
var mail = array[4];
record = new Record { Id = id, Login = login, Number = number, Name = name, Mail = mail };
return true;
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
}
record = null;
return false;
}
public int CompareTo(Record other)
{
return string.Compare(this.Login, other.Login, StringComparison.Ordinal);
}
public bool Equals(Record other)
{
return this.Id.Equals(other.Id) || this.Login.Equals(other.Login) || this.Number.Equals(other.Number);
}
public override string ToString()
{
return string.Format("{0};{1};{2};{3};{4}", this.Id, this.Login, this.Number, this.Name, this.Mail);
}
}
}
Pozdrawiam,
mr-owl