Question

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?

Était-ce utile?

La solution

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).

Autres conseils

Any reason not to use

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

etc?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top