I have a list:
{CT, MA, VA, NY}
I pass this list to a function and get a list of optimal waypoints
{2,0,1,3}
Now I need to rearrange the list according to the order that was recently provided. those. after rearrangement, the list should look like this:
{VA, CT, MA, NY}
What is the best way to do this? Is there a way using linq?
You can try the following:
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();
This seems like the easiest way:
oldItems = LoadItems(); //{"CT","MA","VA","NY"}; List<string> newItems = List<string>(); foreach(int idx in returnedIndexes) { newItems.Add(oldItems[idx]); }
Source: https://habr.com/ru/post/945093/More articles:Sleep using GROUP BY and RETURN ENTITY LIST - javaUpdated iOS App - New Leaders and Achievements - iosLatest compatible versions of Nutch and Solr - solrMultilevel regression model for multiplied data in R (Amelia, zelig, lme4) - rInvalid javascript regex range in character class - javascript.SD to data.table in R - rVim - search for a pattern in the current line ONLY - macrosAttempting to read or write protected memory in a .NET application - c #Create n rows from NULL in PostgreSQL - postgresqlCloudBees Availability Zones and Disaster Recovery - javaAll Articles