C# 使用未分配的局部变量';folderPath';

C# 使用未分配的局部变量';folderPath';,c#,C#,我有一个错误: 使用未分配的局部变量“folderPath” 当我使用此代码时: string folderPath = folderPath.Substring(folderPath.IndexOf(@"\") + 1) + @"C:\test\" + "_converted"; 如何解决它?您正在创建一个字符串,并在该过程中尝试访问它。那没有道理 如果folderPath是一个现有变量,请重用该变量: folderPath = folderPath ... 或使用其他名称创建变量: st

我有一个错误:

使用未分配的局部变量“folderPath”

当我使用此代码时:

string folderPath = folderPath.Substring(folderPath.IndexOf(@"\") + 1) + @"C:\test\" + "_converted";

如何解决它?

您正在创建一个字符串,并在该过程中尝试访问它。那没有道理

如果
folderPath
是一个现有变量,请重用该变量:

folderPath = folderPath ...
或使用其他名称创建变量:

string folderPath2 = folderPath ...

您正在创建一个字符串,并在该过程中尝试访问它。那没有道理

如果
folderPath
是一个现有变量,请重用该变量:

folderPath = folderPath ...
或使用其他名称创建变量:

string folderPath2 = folderPath ...