排序字符串列表的最快方法

编程入门 行业动态 更新时间:2024-10-27 10:22:21
本文介绍了排序字符串列表的最快方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有这样的字符串列表

名字-姓氏"(用短划线-隔开)

"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]);

更多推荐

排序字符串列表的最快方法

本文发布于:2023-10-18 03:26:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1502944.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   最快   方法   列表

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!