我的问题是我如何必须在 lambda 表达式中转换一个对象,List<ExportData>
以便我可以直接访问AddressByte
成员class CyclicData
?
请不要描述我已经做过的没有 lambda 的任何解决方案。我的问题是这是否可以在一行代码中使用 lambda?
public class ExportData
{
public string Designation { get; set; }
}
public class StaticData : ExportData
{
public string Value { get; set; }
}
public class CyclicData : ExportData
{
public string Block { get; set; }
public string Typ { get; set; }
public string AddressByte { get; set; }
public string AddressBit { get; set; }
}
public void getMemberFromList()
{
List<ExportData> list = new List<ExportData>();
list.Add(new CyclicData());
list.Add(new StaticData());
list.Add(new StaticData());
// get addressByte form Cyclic object with one line of code
string addressByte = list.Where(x => x.GetType() == typeof(CyclicData)).FirstOrDefault().AddressByte;
//-> does not work because of missing cast to CyclicData;
}
有谁知道是否以及如何做到这一点?