Created
March 21, 2012 15:41
-
-
Save masaru-b-cl/2148687 to your computer and use it in GitHub Desktop.
Cast to Datetime from generic type value.
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; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace ConsoleApplication1 | |
{ | |
class Program | |
{ | |
private static void Write<T>(T value) | |
{ | |
if (value is DateTime) | |
{ | |
var datetime = (DateTime)((object)value); | |
Console.WriteLine(datetime.ToString("yyyyMMddHHmmss")); | |
} | |
else | |
{ | |
Console.WriteLine(value); | |
} | |
} | |
static void Main(string[] args) | |
{ | |
Write(DateTime.Now); | |
Write(1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment