Frage

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?

War es hilfreich?

Lösung

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

Andere Tipps

Any reason not to use

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

etc?

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top