重新排列的基础上在C#中给定的顺序列表 [英] Rearrange a list based on given order in c#
本文介绍了重新排列的基础上在C#中给定的顺序列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个列表如下:
{CT, MA, VA, NY}
我此名单提交一个功能,我获得最佳的航点顺序列表
I submit this list to a function and I get the optimum waypoint order list
{2,0,1,3}
现在我要重新排列列表按照该新设置的顺序。即重新排列后,该清单应该是这样的:
Now I have to rearrange the list as per the order that is newly provided. i.e. after rearranging, the list should look like:
{VA, CT, MA, NY}
什么是做到这一点的最佳方法是什么? ?使用LINQ是有办法
What is the optimum way to do it? Using linq is there a way?
推荐答案
您可以尝试以下操作:
var list = new List<string>{"CT", "MA", "VA", "NY"};
var order = new List<int>{2, 0, 1, 3};
var result = order.Select(i => list[i]).ToList();
这篇关于重新排列的基础上在C#中给定的顺序列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文