Dienstag, 2. Februar 2010

C# Tipps

1.Using List.find Method
http://msdn.microsoft.com/en-us/library/x0b5b5bc.aspx

2.String to int: int x = Int16.Parse("23");
int to string: x.toString();

3.String <--> DateTime change:

// String to DateTime
String MyString;
MyString = "1999-09-01 21:34 PM";
//MyString = "1999-09-01 21:34 p.m."; //Depends on your regional settings

DateTime MyDateTime;
MyDateTime = new DateTime();
MyDateTime = DateTime.ParseExact(MyString, "yyyy-MM-dd HH:mm tt",
null);


//DateTime to String
MyDateTime = new DateTime(1999, 09, 01, 21, 34, 00);
String MyString;
MyString = MyDateTime.ToString("yyyy-MM-dd HH:mm tt");

//Compare
DateTime dt1 = new DateTime(2006, 01, 24);
DateTime dt2 = new DateTime(2006, 01, 23);
if (DateTime.Compare(dt1, dt2) < 0)
{
Console.WriteLine("second date is larger than the first date");
}
else if (DateTime.Compare(dt1, dt2) == 0)
{
Console.WriteLine("second date is same as first date");
}
else
{
Console.WriteLine("second date is smaller than the first date");
}


Yestoday:

static DateTime GetYesterday()
{
// Add -1 to now
return DateTime.Today.AddDays(-1);
}

Tomorrow:

static DateTime GetTomorrow()
{
return DateTime.Today.AddDays(1);
}


4.Unterstützen keine Mehrfachvererbung, nur Schnittstelle
http://forum.vb-paradise.de/sonstiges/off-topic/9463-c-mehrfachvererbung-nur-ueber-interfaces/

Keine Kommentare: