我有一个 Room 对象列表,每个房间对象都有一个 Building 属性;
public class Room
{
public string BuildingName;
public string Name
}
我现在想过滤我的收藏,我只从每栋建筑物中取 1 个房间(我不在乎哪一个)
所以例如
var room = new Room(){BuildingName ="Building 1", Name = "Room 1"};
var room2 = new Room(){BuildingName ="Building 1", Name = "Room 2"};
var room3 = new Room(){BuildingName ="Building 2", Name = "Room 3"};
var room4 = new Room(){BuildingName ="Building 2", Name = "Room 4"};
var room5 = new Room(){BuildingName ="Building 2", Name = "Room 5"};
var ListofRooms = new List<Room> {room, room2, room3, room4, room5};
在这种情况下,我想通过一个函数运行这个列表,该函数将返回一个包含 2 个项目的数组(每个建筑物一个)