如果我想在整个程序中使用方法中的字符串,有人可以给我一个例子吗?我希望能够在程序的其他部分使用 fullName 值。
使困惑..
我想我仍然不明白如何正确调用它,因为我正在获取 FullNameNotinitialized。
public class FindFile
{
public static string fullName;
public static string FullName
{
get
{
if (fullName == null)
throw new FullNameNotInitialized();
return fullName;
}
set
{
fullName = value;
}
}
public class FullNameNotInitialized : Exception
{
public FullNameNotInitialized()
: base() { }
public FullNameNotInitialized(string message)
: base(message) { }
public FullNameNotInitialized(string format, params object[] args)
: base(string.Format(format, args)) { }
public FullNameNotInitialized(string message, Exception innerException)
: base(message, innerException) { }
public FullNameNotInitialized(string format, Exception innerException, params object[] args)
: base(string.Format(format, args), innerException) { }
}
public void sourceFinder()
{
string partialName = "APP";
DirectoryInfo hdDirectoryInWhichToSearch = new DirectoryInfo(@"/");
FileInfo[] filesInDir = hdDirectoryInWhichToSearch.GetFiles("*" + partialName + "*.*");
foreach (FileInfo foundFile in filesInDir)
{
string fullName = foundFile.FullName;
System.Diagnostics.Debug.WriteLine(fullName);
}
MessageBox.Show(fullName);
}
public void show()
{
MessageBox.Show(fullName);
}
}
}