你能解释一下element
数组声明背后的语法吗?这是一个锯齿状的阵列吗?在这种情况下,Value
和Type
是什么?
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}");
}
}
答案 0 :(得分:5)
让我们从内到外:elements
数组的项目
new { Value = 1, Type = typeof(Color) }
是匿名类型实例(包含Value
的两个属性:int
和{{1}类型的Type
});有关详细信息,请参阅https://msdn.microsoft.com/en-us/library/bb397696(v=vs.90).aspx
Type
数组
elements
是此类匿名类型实例的简单 1d 数组
答案 1 :(得分:2)
这是一个锯齿状阵列吗?
没有。它是一个匿名对象的一维数组。
在这种情况下,
SELECT adw."adwords" as "Type", adw."campaignID_adwords" as "campaignID", adw."impressions_adwords"as "impression", adw."CTR_adwords" as "CTR" FROM "adwords" adw UNION select skl."sklik" as "Type", skl."Campaign_id_sklik" as "campaignID", skl."impressions_sklik" as "impression", (case when skl."impressions_sklik" = 0 then 0 when skl."clicks_sklik" = 0 then 0 when skl."clicks_sklik" = '' then 0 when skl."impressions_sklik" = '' then 0 ELSE (iff(skl."clicks_sklik" = 0 or skl."clicks_sklik" IS NULL or skl."clicks_sklik" = '', 0, skl."clicks_sklik") / iff(skl."impressions_sklik" = 0 or skl."impressions_sklik" IS NULL or skl."impressions_sklik" = '', 0, skl."impressions_sklik")) END) as "CTR" FROM "sklik" skl UNION select fad."facebook_ads" as "Type", fad."cam_campaign_id_facebook_ads" as "campaignID", fad."cam_impressions_facebook_ads" as "impression", fad."cam_ctr_facebook_ads" as "CTR" FROM "facebook_ads" fad
和Value
是什么?
匿名类的属性。