您只需要有关List / LINQ等的建议
public static List<Employee> Employees()
{
return Adapters.WebServiceAdapter.getInstance.SELECT_EMPLOYEES().ToList();
}
这将以USERID的ASC顺序返回USERID,USERNAME,如下所示
USERID USERNAME
1 FirstUser
2 SecondUser
3 ThirdUser
4 FourthUser
5 FifthUser
我需要根据当前登录的Employee重新排列输出。
例如,我的网站中有USERID 4TH已记录的信息,然后是此功能 应该回来我
USERID USERNAME
4 FourthUser
1 FirstUser
2 SECONDUSER
3 THIRDUSER
5 FIFTHUSER
只是为了说明我为什么这样做 - 我在我的网站上有一个下拉各种各样的地方,我想确保如果调用此函数来加载我的下拉列表。默认情况下,默认情况下应选择当前登录的用户。
如果有人能提供有价值的投入,我感激不尽。
答案 0 :(得分:1)
Just combine two lists using Union
链接代码:
var numbers = new List<Int32>{1,2,3,4,5};
var loggedInUsers = numbers.Where(x=>x == 4);
var restOfUsers = numbers.Where(x=>x != 4);
var joinedLists = loggedInUsers.Union(restOfUsers).ToList();
答案 1 :(得分:0)
你也可以尝试这个技巧: 将已登录的用户插入列表的第0位,然后调用distinct。
MyList.Insert(0,MyList.Single(c => c.UserID == IDofLoggedUser));
var lst = MyList.Distinct();
结果:
the original list ordered by ID like you have
MyList = 1,2,3,4,5,6;
then insert for example logged user has ID of 4
MyList = 4,1,2,3,4,5,6;
then call distinct,it will find and maintain the first 4,and remove second 4, so final result:
MyList = 4,1,2,3,5,6;