This question is pretty much the opposite of this question: Does C# have built-in support for parsing page-number strings?
So given
1,3,5,6,7,8,9,10
Had to solve same problem. Was finding alternatives to my solution which I think looks more logical. Therefore sharing it. Set second parameter to true if you want to sort an unsorted list.
public string ToRangeString(List list, bool withSort) {
list = list.Distinct().ToList();
if(withSort) list.Sort();
StringBuilder result = new StringBuilder();
int temp;
for (int i=0; i