Advertisement
Statev

AnonymousMethod

Mar 8th, 2012
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.42 KB | None | 0 0
  1. using System;
  2. class Anonymous
  3. {
  4.     public static object ReturnAnonymous()
  5.     {
  6.       return new { City="Prague", Name="Tomas" };
  7.     }
  8.  
  9.     static void Main(string[] args)
  10.     {
  11.         object o = ReturnAnonymous();
  12.         var types = Cast(o, new { City = "", Name = "" });
  13.         Console.WriteLine(types.City);
  14.     }
  15.  
  16.     public static T Cast<T>(object obj, T type)
  17.     {
  18.         return (T)obj;
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement