Tuesday, June 14, 2011

StreamReader r = File.OpenText("cars.txt");
TextWriter tw = new StreamWriter("date.txt");
tw.WriteLine(System.DateTime.Now);
tw.WriteLine(new ad(r.ReadLine().Trim()));
r.Close();
tw.Close();

class ad
{
public ad(string dataLine)
{
string[] temp = dataLine.Split('|');
Phone = temp[0];
Model = temp[1];
Modif = temp[2];
Year = temp[3];
Price = temp[4];
Date = temp[5];
Note = temp[6];
}
public string Phone { get; set; }
public string Model { get; set; }
public string Modif { get; set; }
public string Year { get; set; }
public string Price { get; set; }
public string Date { get; set; }
public string Note { get; set; }
public override string ToString()
{
return string.Join("|", new object[]{Phone, Model, Modif, Year, Price, Date, Note});
}
}

public static class Bla123
{
public static T? To(this string val, CultureInfo culture = null)
where T : struct, IConvertible
{
if (culture == null)
{
culture = CultureInfo.CurrentCulture;
}

T? result = null;
if (!string.IsNullOrEmpty(val))
{
try
{
result = (T)Convert.ChangeType(val, typeof(T), culture);
}
catch { }
}

return result;
}
}

No comments:

Post a Comment