I have IP table with 2 columns: IP and % what is the best way to sort this table according IP precent ?
table type:
public List<string> statistics()
{
}
I have IP table with 2 columns: IP and % what is the best way to sort this table according IP precent ?
table type:
public List<string> statistics()
{
}
Assuming your IpAddress
column is a string and you just want that column value sorted by percentage descending (a lot of assumptions since your question is vague):
List<string> ips = IpTable.OrderByDescending(x=> x.Percentage)
.Select(x=> x.IpAddress)
.ToList();
You'll have to split the string into two columns, parse the second column into numbers and then orderby that column.
return from line in statistics
let split = line.Split('\t', '%')
let percentage = double.Parse(split[1])
orderby percentage
select line;
In this code, you'll have to replace the splitting characters by whatever character(s) you have in each of your lines and replace the column I'm indexing as well, but the rest should work as you need.
I think every entry in your list is a string - if not just ignore the following...
You first have to parse this into another format - don't know if this is true but I think there is a tab ('\t') between the Ip's and your percent, so you could start by doing something like
var stringTupleList =
myList.Select(s => s.Split('\t'))
.Select(ar => new { Ip = ar[0], PercentString = ar[1] });
This gives you a list of anonymous types and you can continue like BrokenGlass answered:
var stringTupleList =
myList.Select(s => s.Split('\t'))
.Select(ar => new { Ip = ar[0], PercentString = ar[1] })
.OrderByDescending(t => t.PercentString)
.Select(t => t.Ip)
.ToList();