开发者

c# IndexOf does not exist in current context

I'm trying to use the following and can't wrap my head around why this IndexOf method isn't开发者_开发技巧 working.

foreach (string s in regKey.GetSubKeyNames())
        {
            RegistryKey sub = Registry.LocalMachine.OpenSubKey(string.Format(@"{0}\{1}", _UninstallKey64Bit, s), false);

            if (sub.ValueCount > 0)
            {
                values = sub.GetValueNames();

                if (IndexOf(values, "DisplayName")  != -1)
                {
                    string name = (sub.GetValue("DisplayName") != null) ? sub.GetValue("DisplayName").ToString() : string.Empty;

                    if (!string.IsNullOrEmpty(name) && (name.ToLower() == appName.ToLower()))
                        if (IndexOf(values, "UninstallString") != -1)
                        {
                            uninstallValue = (sub.GetValue("UninstallString") != null) ? sub.GetValue("UninstallString").ToString() : string.Empty;
                            break;
                        }
                }
            }
        }

Can anyone lend me a hand with this?


Correct syntax is:

if (Array.IndexOf(values, "DisplayName")  != -1)


GetValueNames() returns a string array so you probably are looking for:

if (values.Contains("DisplayName"))


Try

 if (values.Any(v => v == "DisplayName")) )
 {
    ...
 }


Try changing -

if (IndexOf(values, "UninstallString") != -1)

to

if (Array.IndexOf(values, "UninstallString") != -1)


Try this instead of just IndexOf.

Array.IndexOf(values, "DisplayName")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜