名称Count在当前上下文中不存在

时间:2012-02-21 14:44:20

标签: c# winforms scope

此方法是名为OSVersion的类的一部分。当我在控制台应用程序中测试它虽然它工作正常。 Count在当前上下文中不存在。任何人都可以对此有所了解。

public static bool  OperatingSystemVersionGet()
        {
            XmlDocument xlDoc = new XmlDocument();
            string sfile =
                @"C:\dev\4.6\RTM\R1\Install\SetupManager\SourceCode.SetupManager\SourceCode.SetupManager\Configs\blackpearl\Product.config";

            xlDoc.Load(sfile);
            XmlNodeList nodeList = xlDoc.SelectNodes("//dependancy");

            List<string> compareList = new List<string>();

            string osv = Environment.OSVersion.VersionString;

            int firstIndex = osv.IndexOf(' ');
            int secondIndex = osv.IndexOf(' ', firstIndex + 1);
            int thirdIndex = osv.IndexOf(' ', secondIndex + 1);

            String osName = osv.Substring(0, thirdIndex);
            String majorVersion = osv.Substring(thirdIndex + 1, 1);
            String minorVersion = osv.Substring(thirdIndex + 3, 1);

            bool isIn = false;

            if (nodeList != null)
                foreach (XmlNode node in nodeList)
                {
                    try
                    {

                            string type = node.Attributes["type"].Value;
                            string name = node.Attributes["name"].Value;
                            string feat = node.Attributes["featureversion"].Value;

                            String[] versionPart = feat.Split('.');

                            string second = versionPart[1];
                            string third = versionPart[2];

                                if (type == "Windows")
                                {
                                    if((name == osName) && ((second == majorVersion) && (third == minorVersion)))
                                    {
                                        compareList.Add(name);
                                    }

                                }


                    }
                    catch(NullReferenceException ex)
                    {
                        //nullReferenceException handled here
                    }
                }

           if(compareList.Count == 0)
            {
                isIn = true;
            }
            else
            {
                isIn = false;
            }
            return isIn;

        }

2 个答案:

答案 0 :(得分:3)

你说你在编译时收到了这个

尝试清理解决方案并重建它。

我看不到任何错误,我在当前项目中复制了您的函数,并且我编译它没有错误!

答案 1 :(得分:0)

您几乎肯定错过了winforms应用的源文件顶部的using System.Collections.Generic