【发布时间】:2015-04-22 22:34:21
【问题描述】:
我想声明和初始化一个字符串变量,它是一个类的本地变量,但可以被该类的所有函数访问。仅供参考,这是一个用于 gui 的应用程序,它将使用文件夹中的多个文本文件。我正在尝试设置一个包含项目目录路径的字符串变量,以便此类中的所有函数都可以访问它。
我提供了一部分代码,包括设置路径的函数以及设置时使用字符串变量的函数。
public class Program
{
private string DirectoryPath;
public static void Main()
{
setPaths();
SetGroundTempArray();
}
public static void setPaths()
{
DirectoryPath = Directory.GetCurrentDirectory();
}
public static void SetGroundTempArray()
{
string groundtempfile = "\\groundtemp.txt";
string groundtempdir = "\\Text Files";
string groundtempFP = DirectoryPath + groundtempdir + groundtempfile;
}
}
【问题讨论】:
-
你有什么问题?
标签: c# private declaration public