-2
List<String> stores = new List<String>();

foreach (XmlNode storeXml in storesXml)
{
stores.Add(storeXml.InnerText); 
 can have string id of for e.g.
 s1, s5, s3, s27
}

result.Sort(); 
Console.WriteLine(stores); 

how do i sort the list so that the list is sorted like {s1, s3, s5, s27}

Captain Obvlious
  • 19,754
  • 5
  • 44
  • 74
Rejuan
  • 9
  • 5
  • 2
    If it is about c#, what do "java" and "c++" tags do here? – user31264 Apr 18 '16 at 23:19
  • 1
    "How do i .... in c#" -- Why is it tagged as C++ and Java? – Dan Mašek Apr 18 '16 at 23:19
  • 1
    Please to not include tags that are completely unrelated to your question. This is considered tag spam and will get you down and close voted very quickly. I have removed the tags for you but please be mindful of what tags you use in future posts. – Captain Obvlious Apr 18 '16 at 23:21

1 Answers1

1

This answer makes some assumptions about the input data.

1)The string will only, and always, have one non-digit character in the first position.

2)The remaining characters will form a proper int.

List<String> stores = new List<String>();
stores.Add("s27");
stores.Add("s3");
stores.Add("s5");
stores.Add("s1");

var sorted = stores.OrderBy(s => int.Parse(s.Substring(1)));

If checks need to be performed, please give complete specification of input strings format.

Luc Morin
  • 5,302
  • 20
  • 39