通过传递整数而不是ShellSpecialFolderConstants

时间:2016-04-29 09:00:18

标签: c#

虽然我知道可以使用Environment.GetFolderPath(Environment.SpecialFolder.Desktop)检索特殊文件夹路径 例如,要检索桌面的路径,我想知道是否有一种方法可以在不传递常量的情况下检索路径(在本例中为“桌面”),而是引用它的整数。

使它更清楚;我想要做的是以下示例: Environment.GetFolderPath(0x00)Environment.GetFolderPath(0)

我想要实现的最终目标是浏览一个只有整数的数组,引用所述特殊文件夹,这样我就可以在一个循环中获取各种特殊文件夹的路径。

1 个答案:

答案 0 :(得分:0)

为什么要让代码的可读性降低?当然你可以使用数字,它是一个枚举 - 但它只是意味着你的代码不太可读,人们需要记住那些不必要的数字

       Desktop = 0,
       Programs = 2,
       Personal = 5,
       MyDocuments = 5,
       Favorites = 6,
       Startup = 7,
       Recent = 8,
       SendTo = 9,
       StartMenu = 11,
       MyMusic = 13,
       MyVideos = 14,
       DesktopDirectory = 16,
       MyComputer = 17,
       NetworkShortcuts = 19,
       Fonts = 20,
       Templates = 21,
       CommonStartMenu = 22,
       CommonPrograms = 23,
       CommonStartup = 24,
       CommonDesktopDirectory = 25,
       ApplicationData = 26,
       PrinterShortcuts = 27,
       LocalApplicationData = 28,
       InternetCache = 32,
       Cookies = 33,
       History = 34,
       CommonApplicationData = 35,
       Windows = 36,
       System = 37,
       ProgramFiles = 38,
       MyPictures = 39,
       UserProfile = 40,
       SystemX86 = 41,
       ProgramFilesX86 = 42,
       CommonProgramFiles = 43,
       CommonProgramFilesX86 = 44,
       CommonTemplates = 45,
       CommonDocuments = 46,
       CommonAdminTools = 47,
       AdminTools = 48,
       CommonMusic = 53,
       CommonPictures = 54,
       CommonVideos = 55,
       Resources = 56,
       LocalizedResources = 57,
       CommonOemLinks = 58,
       CDBurning = 59

显然Merion Huhges觉得你太愚蠢了,无法自己将Environment.GetFolderPath((Environment.SpecialFolder)20);应用到你的代码中。