小编dog*_*ter的帖子

如何使用 LINQ 从另一个列表填充对象的属性

我有 2 个对象列表。一个有值,另一个有名称和值。我想查找另一个列表中的值并将结果写入 pref.Name。我知道我可以用 foreach 来做到这一点,但我认为在 LINQ 中有一种很好的方法可以做到这一点。想法?

public class Preference
    {
        public string Category { get; set; }
        public string Name { get; set; }
        public string ItemValue { get; set; }
        public int SortOrder { get; set; }
    }

public class SAPReadOnlyItem
    {
        public string Category { get; set; }
        public string Name { get; set; }
        public string ItemValue { get; set; }
    }

    List<Preference> preferences = getExistingUserPreferences(UserID, ddlCategory.SelectedValue); //this list is just keys
    List<SAPReadOnlyItem> sapReadOnlyItems = …
Run Code Online (Sandbox Code Playgroud)

c# linq

4
推荐指数
1
解决办法
8753
查看次数

标签 统计

c# ×1

linq ×1