0
假设我有一个类,其中包含属性int Id,int Height,int NumberOfFloors。将字典<Int, Object>转换为包含lambdas的字典<Int,Object.Property>
如果我有一个字典,其中每个键是建筑物ID。有没有办法将它转换成字典,其中每个键是建筑物ID,每个值是楼层数。显然这是循环可行的。只是想知道是否有一种简单的方法来使用lambdas来做到这一点?
谢谢!
var intToBuilding = new Dictionary<int, Building>(); //pretend populated
var intToInt = new Dictionary<int, int>();
foreach(var intBuilding in intToBuilding)
{
var building = userPreference.Value;
intToInt.Add(intBuilding.Key, building.Height);
}