【发布时间】:2013-04-01 03:09:43
【问题描述】:
我正在尝试运行此代码来替换一个字符串,但是当我这样做时,它给了我一个错误提示
Error 1 A local variable named 'typeval' cannot be declared in this scope because it would give a different meaning to 'typeval', which is already used in a 'parent or current' scope to denote something else
这是代码
public static string Replace(string typeval)
{
string newType = "";
string typeval = "";
if (typeval.Equals("User Service Request"))
{
newType = typeval.Replace("User Service Request", "incident");
}
else if (typeval.Equals("User Service Restoration"))
{
newType = typeval.Replace("User Service Restoration", "u_request");
}
return newType;
}
【问题讨论】:
-
而且这个错误信息还不足以提示你也许应该尝试重命名两个
typevals 之一? -
为变量 typeval 赋予不同的名称。错误是您已经在父级中使用了具有此名称的变量。只需更改此变量的名称即可解决您的问题
-
建议您以后搜索此类错误。