[英]what exactly new {} doing in a lambda expression?
i was going through a code and found following lines of code i was unable to understand... 我正在检查代码,发现以下几行代码我无法理解...
objDashBoardHierarchyInfo = SubscribeList.GroupBy(x = > new {
ReportID = x.ReportId, ReportName = x.ReportName, Direction = x.DisplayColumn
})
.Select(x = > new DashBoardHierarchyInfo {
ReportID = x.Key.ReportID,
ReportName = x.Key.ReportName,
DisplayDirection = x.Key.Direction ? ? 0,
oListDashBoardReportInfo = x.Select(c = > new DashBoardReportInfo {
DataSourceObjectName = c.DataSourceObjectName,
ReportSubType = c.OutputType,
DataSourceId = c.DataSourceId,
XvalueFeild = "",
YvalueFeild = "",
ReportName = c.ReportName,
BodyId = c.BodyID,
ReportID = c.ReportId,
UserDashboardReportId = c.UserDashboardReportId,
ChartTypeID = c.ChartTypeID,
SeriesColor = c.Color,
SeriesControlTypeId = c.ControlType ? ? 0
}).ToList < DashBoardReportInfo > ()
}).ToList < DashBoardHierarchyInfo > ();
The new { }
create an anonymous type for you and also create object of that anonymous type that is returned. new { }
为您创建一个匿名类型,并且还创建返回该匿名类型的对象。 You can read more about anonymous type on this MSDN article . 您可以在此MSDN文章上阅读有关匿名类型的更多信息。
The statement you are asking about create object of anonymous type using the SubscribeList
object being pass through lambda
. 您正在询问使用通过
lambda
传递的SubscribeList
对象的匿名类型创建对象的语句。
new { ReportID = x.ReportId, ReportName = x.ReportName, Direction = x.DisplayColumn }
You can create object of anonymous type without lamda as show under. 您可以创建没有lamda的匿名类型的对象,如下所示。
var myObj = new {Id=1, Name="abc"};
Console.WriteLine(myObj.Id);
Console.WriteLine(myObj.Name);
new { }
syntax creates instance of anonymous type . new { }
语法创建匿名类型的实例。
new { ReportID = x.ReportId, ReportName = x.ReportName, Direction = x.DisplayColumn }
means that I want to group this list by every possible combination of three properties ReportID
, ReportName
, DisplayColumn
. 表示我想按三个属性
ReportID
, ReportName
和DisplayColumn
每种可能组合将此列表分组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.