如何对列表进行排序<string>/字符串版本号数组? [英] How to sort a list&lt;string&gt; / array of string version number?

查看:53
本文介绍了如何对列表进行排序<string>/字符串版本号数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个版本字符串列表(见照片),我想按降序对它们进行排序.

I have a list of strings of version (see photo), and I'd like to sort them in descending order.

我已经看到一些使用 Version 类来比较它们的解决方案,但我想不出任何解决方案可以像这样对整个列表进行排序.实现这一目标的最简单的方法是什么?

I've seen a few solutions using Version class to compare them, but I can't think of any solution that sort a whole list like this. What is the least complicated way to achieve this?

推荐答案

这个简单的实现有什么问题?

what is wrong with this simple implementation?

using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var ver = new List<Version>();

            ver.Add(new Version("3.5"));
            ver.Add(new Version("3.15"));
            ver.Add(new Version("3.10"));
            ver.Add(new Version("3.1"));

            ver.Sort();
            ver.Reverse();
        }
    }
}

这篇关于如何对列表进行排序<string>/字符串版本号数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆