读取注册表键值,保存为字符串
reg--
|--TaskID 0x00032d
|--TaskName MyTaks代码如下,读取注册表键名为TaskID的项,调试代码发现明明已经找到键名TaskID,
并复值给cs了,但是CompareTo()就是认为cd字符串不为"TaskID"
不能返回true. 请问我的代码哪有问题?RegistryKey rksub = ..............;
String[] sta = rksub.GetValueNames();
for(int i=0;i<sta.Length;i++)
{
String cs = sta[i];
if(cs.CompareTo("TaskID")==0) ///??????????
{
return true;
}
}
reg--
|--TaskID 0x00032d
|--TaskName MyTaks代码如下,读取注册表键名为TaskID的项,调试代码发现明明已经找到键名TaskID,
并复值给cs了,但是CompareTo()就是认为cd字符串不为"TaskID"
不能返回true. 请问我的代码哪有问题?RegistryKey rksub = ..............;
String[] sta = rksub.GetValueNames();
for(int i=0;i<sta.Length;i++)
{
String cs = sta[i];
if(cs.CompareTo("TaskID")==0) ///??????????
{
return true;
}
}
直接用等号就行啊if(sta[i] == "TaskID")
{
return true;
}
我把代码都贴上来private uint GetRegRecord(bool iPenOperType)
{
RegistryKey rkLocalM = Registry.LocalMachine;
const string strSubKey = @"SOFTWARE\Mytest\reg";
RegistryKey rkSub = rkLocalM.OpenSubKey(strSubKey, true); if (rkSub != null)
{
string[] strData = rkSub.GetValueNames();
for (int i = 0; i < strData.Length; i++)
{
String cs = strData[i];
if(cs=="TaskID")//????????就是这里,总认为cs字符串不为 "TaskID "
return Convert.ToUInt32(rkSub.GetValue(strData[i]).ToString());
}
}
return 0;
}拜托
if(cs== "TaskID ")
改成
String cs = "TaskID "
if(cs== strData[i])这样看下