I have some code block, and need to use the same object to be used outside the block, I can use a strong types such as:
Person p = null;
if(cond1)
{
p = new Person();
p.Name = "Name1";
p.Age = 25;
}
else if (cond2)
{
p = Employees.Select(c=>new Person() {Name = c.FirstName + " " +c.LastName }).First();
p.Age = 23;
}
if(p != null)
{
Console.Write(p.Name);
}
I need to do that via anonymous types instead of person, I can’t use tuples because the property names are not named, and can’t create tinny classes every time I need such thing, this is a very simple case, but what about LINQ results in blocks similar to my example?
How about this kind of thing