Skip to content

Instantly share code, notes, and snippets.

@masaru-b-cl
Created March 21, 2012 15:31
Show Gist options
  • Save masaru-b-cl/2148515 to your computer and use it in GitHub Desktop.
Save masaru-b-cl/2148515 to your computer and use it in GitHub Desktop.
Cast to Generic Type
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
private static void Write<T>(object o)
{
var hoge = (T)o;
Console.WriteLine(hoge);
}
static void Main(string[] args)
{
object o = DateTime.Now;
Write<DateTime>(o);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment