我觉得我一直在看我的代码。
但我的问题是,我有一个无序列表,我需要选择与输入最接近或等于一个数字的对象。
我创建了这个小样例来说明我要做什么。
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
}
var persons = new List<Person>
{
new Person {Age = 10, Name = "Aaron"},
new Person {Age = 15, Name = "Alice"},
new Person {Age = 20, Name = "John"},
new Person {Age = 22, Name = "Bob"},
new Person {Age = 24, Name = "Malcom"}
};
int i = 17; //should return 'Alice 15'
int y = 22; //should return 'Bob 22