プログラム全体でメソッドの文字列を使用したい場合、誰かに例を教えてもらえますか? プログラムの他の部分で 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);
}
}
}