[英]How can I retrieve a list of objects from database from a list of complex types?
[英]How can I retrieve all property values from a list of common objects?
我想從集合中檢索所有單個屬性作為數組:
class Foo{
public string Bar { get; set; }
public string Baz { get; set;}
}
我想從集合中獲取所有Bar屬性
var list = new List<Foo>();
string[] allBars = list. ....
以及如何進行???
謝謝你的幫助。
您可以使用:
string[] allBars = list.Select(foo => foo.Bar).ToArray();
如果您特別需要將其轉換為數組,則僅將其轉換為數組。 如果您的目標只是輸出“ Bar”列表,則可以執行以下操作:
var allBars = list.Select(foo => foo.Bar); // Will produce IEnumerable<string>
foreach(var bar in allBars)
{
// Do something with bar
}
var query = from foo element in foo_bar_list
where foo.Bar == ""
select new
{
class1.Baz
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.