我试图运行此代码替换字符串,但是当我这样做,给了我一个错误说C#替换字符串
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;
}
而这个错误信息不足以给出提示,也许你应该尝试重命名两个'typeval'中的一个? – Jon 2013-04-09 15:34:25
给变量typeval以不同的名称。错误是你已经在Parent中使用了带有这个名字的变量。只是改变这个变量的名称将解决你的问题 – 2013-04-09 15:34:37
它建议你在将来寻找这样的错误。 – 2013-04-09 15:38:18