Could you please explain me the syntax behind element array declaration ? Is this a jagged array ? What are Value and Type in this case ?
enum Color { Red = 1, Green, Blue }
enum Theme { Dark = 1, Light, NotSure }
public static void Main(string[] args)
{
var elements = new[]
{
new { Value = 1, Type = typeof(Color) },
new { Value = 2, Type = typeof(Theme) },
new { Value = 3, Type = typeof(Color) },
new { Value = 1, Type = typeof(Theme) },
new { Value = 2, Type = typeof(Color) },
};
foreach (var element in elements)
{
var enumValue = Enum.ToObject(element.Type, element.Value);
Console.WriteLine($"{element.Type.Name}({element.Value}) = {enumValue}");
}
}
Let's go from inner to outer: elements array's items
new { Value = 1, Type = typeof(Color) }
are anonymous type instances (with two properties: Value of type int and Type of type Type); see https://msdn.microsoft.com/en-us/library/bb397696(v=vs.90).aspx for details
elements array
var elements = new[] {
new { Value = 1, Type = typeof(Color) },
new { Value = 2, Type = typeof(Theme) },
...
};
is a simple 1d array of such anonymous type instances
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With