new{ Name = "aaa", Number = 123 }
- var a = getAnonimusInstance();
- Console.WriteLine(a.Name);
- var b = getAnonimusInstance();
- Console.WriteLine(b.Number == a.Number); //где a и b имеют анонимный тип, описанный выше.
* This source code was highlighted with Source Code Highlighter.
dynamic GetAnonimusInstance()
{
return new {Name = "aaa", Number = 123};
}
class Program
{
static object ReturnAnonymous()
{
return new { Name = "aaa", Number = 123 };
}
static Func<T> Cast<T>(object obj, T type)
{
return () => (T)obj;
}
static void Main(string[] args)
{
object o = ReturnAnonymous();
var getAnonimusInstance = Cast(o, new { Name = "", Number = 0 });
var a = getAnonimusInstance();
Console.WriteLine(a.Name);
var b = getAnonimusInstance();
Console.WriteLine(b.Number == a.Number); //где a и b имеют анонимный тип, описанный выше.
}
}
* This source code was highlighted with Source Code Highlighter.