简体   繁体   中英

C#/VB.Net - Enumerate Path

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

在此处输入图片说明

在此处输入图片说明

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM