本文介绍了排序字符串列表的最快方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的字符串列表
名字-姓氏"(用短划线-隔开)
"FirstName-Lastname" (separated by a dash -)
我需要按照名字然后按姓氏对这个列表进行排序
I need to sort it this list by first name and then by last name
执行此操作的最佳方法是什么. 我需要在不到1秒的时间内处理30000个字符串.
What is the best way to do this. i need to process 30000 strings in less than 1 second.
有人建议我对实体使用LINQ.
I was suggested to use LINQ to Entities.
什么是最好的使用方式?
what is the best way to use this?
非常感谢您的帮助
为避免混淆,输入为List<string>
推荐答案您可以使用LINQ(无需修改列表中的数据即可进行排序):
You could use LINQ (which would allow you to sort without modifying the data in the List):
names.OrderBy(s => s.Split('-')[0]).ThenBy(s => s.Split('-')[1]);更多推荐
排序字符串列表的最快方法
发布评论