An example of enumeration application is as follows: the name and path of a special folder are output through loop traversal ., Enumeration example
You can use the Environment. GetFolderPath (Environment. SpecialFolder folder) method to obtain the path of a special folder in the current windows system. Then, how do I pass in different enumerated values and execute this method repeatedly to get the path of the corresponding special folder?
Although repeated writing in one sentence can be achieved, it is not elegant enough. The following is implemented using the Type Static Method Parse.
Requirement: cyclically traverse the names and paths of special folders in the output system.
1 Type enumType = typeof (Environment. specialFolder); 2 string [] enumNames = Enum. getNames (enumType); 3 foreach (string enumName in enumNames) 4 {5 string enumValue = Environment. getFolderPath (Environment. specialFolder) (Enum. parse (enumType, enumName); 6 Console. writeLine (enumName + "folder: \ r \ n \ t" + enumValue); 7 8} 9 Console. readKey ();
Execution result: