我对 Foreach 循环不太了解
我有 4 个字符串变量,我将 app.config 中的加密值存储在这些变量中。我的工作是检测这 4 个变量中是否有数据。即使没有值,我也想将默认加密值传递给它.我开始这样做......
string EncValue = oEncrypt.EncryptBase64String("NO Data Found");
UpdateOrCreateAppSetting("UserName", ref MPScmUserName);
UpdateOrCreateAppSetting("Password", ref MPScmPassword);
UpdateOrCreateAppSetting("DBUserName", ref MPDbUserName);
UpdateOrCreateAppSetting("DBPassword", ref MPDbPassword);
var list5 = from docs in doc1.Descendants("appender").Elements()
where docs.Name == "file"
select docs;
var element5 = list5.FirstOrDefault();
MPLoadAppConfig = appConfigFile1;
MPErrorLog = element5.Attribute("value").Value;
string[] namesArray = new string[] {
MPScmUserName,MPScmPassword,MPDbUserName,MPDbPassword};
foreach (string i in namesArray)
{
if (i is string)
{
if (i == "")
{
i = EncValue.ToString();
}
}
}
我应该如何为该数组中的字符串分配默认加密值,该字符串是一个空字符串。请帮我....