开发者

How to find an object from a List of objects?

开发者 https://www.devze.com 2023-02-17 07:26 出处:网络
I got a list of columns in the variable ParentColumnNames, i need to find a single Column object within this list using the selectedvalue of another combobox. How can i get that? Please help...

I got a list of columns in the variable ParentColumnNames, i need to find a single Column object within this list using the selectedvalue of another combobox. How can i get that? Please help...

List&开发者_JAVA技巧lt;Columns> ParentColumnNames = new List<Columns>();
     ParentColumnNames = metadataobj.GetColumns(cbParentTable.SelectedItem.ToString());

within this i need to find single object using cbParentColumn.SelectedValue.


Try something like this:

ParentColumnNames.Where(x => x.Name == cbParentColumn.SelectedValue).FirstOrDefault();

My answer assumes that the Columns class has a property Name and that this property contains the value you are looking for.

0

精彩评论

暂无评论...
验证码 换一张
取 消