我正在尝试访问 using 语句之外的字符串,其值在 using 语句中分配,如下所示。
我收到错误“使用未分配的局部变量'savedUrl'”。
customItem.name = ld.Name;
customItem.Location = new GeoCoordinate(ld.Latitude, ld.Longitude, 0);
string savedUrl;
using (IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication())
{
if (iso.FileExists(string.Format("{0}.jpeg", ld.Title)))
{
savedUrl = string.Format("{0}.jpeg", ld.Title);
}
}
addSignPosts();
addLabel(ARHelper.AngleToVector(customItem.Bearing, WCSRadius), customItem.name, savedUrl);
如您所见,我在 using 语句之外声明了字符串“savedUrl”,以便它在 using 语句之外具有范围。但似乎在 using 语句中分配它时我无法访问它。
我尝试将其更改为全局变量。但它不起作用,这也是一种不好的做法。
那我该怎么办?我在这里错过了什么吗?
或者有什么解决方法吗?