📌  相关文章
📜  c# 从列表中选择第一个值 - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:56.689000             🧑  作者: Mango

代码示例1
lstComp.First();
//You can also use FirstOrDefault() just in case lstComp does not contain any items.

//To get the Component Value:
var firstElement = lstComp.First().ComponentValue("Dep");

//This would assume there is an element in lstComp. An alternative and safer way would be...
var firstOrDefault = lstComp.FirstOrDefault();
if (firstOrDefault != null) 
{
    var firstComponentValue = firstOrDefault.ComponentValue("Dep");
}