質問

How can I get the path variable very clear in a enumeration for appdata, temp and winddir? I tried this:

enter image description here

enter image description here

But the enumeration wont allow me to use a non-constant expression But I still like to have the folders clean and structured listed in an enumeration, any workarrounds for this problem?

役に立ちましたか?

解決

You aren't going to be able to do that with an enum, but you could with a class:

public class MyFolder
{
    public static String Windows {get {return System.Environment.GetEnvironmentVariable("windir");}}
    public static String AppData {get {return System.Environment.GetEnvironmentVariable("appdata");}}
    public static String Temp {get {return System.Environment.GetEnvironmentVariable("temp");}}
}

I made it static so you could access like you do an enum (ie MyFolder.Windows).

他のヒント

Any reason not to use

string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

etc?

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top