Skip to content

Instantly share code, notes, and snippets.

@chakrit
Created April 6, 2012 12:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chakrit/2319253 to your computer and use it in GitHub Desktop.
Save chakrit/2319253 to your computer and use it in GitHub Desktop.
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