Created
April 6, 2012 12:11
-
-
Save chakrit/2319253 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace DummyCSharp | |
{ | |
class MainClass | |
{ | |
public static void Main (string[] args) | |
{ | |
MyDateTime now = DateTime.Now; | |
Console.WriteLine ("Today's date is: " + (string)now); | |
} | |
} | |
public class MyDateTime | |
{ | |
private DateTime _datetime; | |
private MyDateTime(DateTime dt) { _datetime = dt; } | |
// implicitly convertible to and from a DateTime | |
public static implicit operator DateTime(MyDateTime mdt) | |
{ | |
return mdt._datetime; | |
} | |
public static implicit operator MyDateTime(DateTime dt) | |
{ | |
return new MyDateTime(dt); | |
} | |
// must be explicitly converted to string | |
public static explicit operator string(MyDateTime mdt) | |
{ | |
return mdt._datetime.ToString ("MM/dd/yyyy"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment