为Registry.LocalMachine做排序 [英] do sorting for Registry.LocalMachine

查看:76
本文介绍了为Registry.LocalMachine做排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码和我一起

i have this code with me

protected void Page_Load(object sender, EventArgs e)
{
    string uninstallKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
    using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(uninstallKey))
    {
        foreach (string skName in rk.GetSubKeyNames())
        {
            using (RegistryKey sk = rk.OpenSubKey(skName))
            {
                    this.Label1.Text += Convert.ToString(sk.GetValue("DisplayName")) + "</br>";
            }
        }
    }
}



它运行正常,并返回预期结果。但是如何根据DisplayName进行排序?


it works fine, and return the expected result. but how can i do the sorting according to "DisplayName"?

推荐答案

看看以下是否有效。你需要使用语句将System.Linq添加到你的文件中。



See if the following works. Youll need to add System.Linq using statement to your file.

string uninstallKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
            using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(uninstallKey))
            {
                string value = rk.GetSubKeyNames().Select(skName => rk.OpenSubKey(skName)).Where(m => m.GetValue("DisplayName") != null).OrderBy(m => m.GetValue("DisplayName")).Aggregate<RegistryKey, string>(null, (current, sk) => current + (Convert.ToString(sk.GetValue("DisplayName")) + "</br>"));
                Console.WriteLine(value);
            }





它获取价值,我不知道它是否是你想要的但是它似乎是在向我订购我理解正确。



It gets values, i have no idea if its what you want but it appears to be ordering to me if i understood you correctly.


这篇关于为Registry.LocalMachine做排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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