このメソッドは、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;
}
compareListを初期化する場所が表示されません。しかし、 'compareList'リストの' Count'要素にアクセスしようとしているかのように見えます。代わりに '.size()'を探していますか? – PenguinCoder
returnを "return compareList.Count> 0"にすることができる点を除いて、問題はありません。 – alexsuslin
@PenguinCoder:10行目の 'compareList'を初期化し、' Count'は 'List'の正しいプロパティです。しかし、 'size'メソッドはありません。 –