
Environment.GetFolderPath returns a path string. It receives an enumerated constant of type Environment.SpecialFolder. It is useful in many C# programs.

First, we see that the Environment.GetFolderPath method must be used with an Environment.SpecialFolder enumerated constant. It returns a string that depends on the user's current operating environment. The string includes the user's login name, which in this case is Sam2.
Environment.SpecialFolderThis C# Environment program demonstrates the GetFolderPath method.
Program that calls GetFolderPath [C#]
using System;
class Program
{
static void Main()
{
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
Console.WriteLine(path);
}
}
Output
Varies depending on the operating environment.
C:\Users\Sam2\DesktopSecond argument. Optionally, you may pass a second argument of type Environment.SpecialFolderOption to the GetFolderPath method. This can be used to tell the .NET Framework to verify the existence of the location. If you specify Create, you can create the directory if it does not exist. I have not found this parameter to be useful.

How fast is the Environment.GetFolderPath method, and is it worth caching? I ran a benchmark program where the GetFolderPath call shown in the above example was run 100 thousand times. The result was that the method required 7179 nanoseconds per call, which is 7 microseconds.
If you stored the result of GetFolderPath in a static string, you could load that in a couple nanoseconds depending on the state of your program. Thus, it would be much faster—3000 times faster—to cache the result of GetFolderPath if it is used frequently.

We examined the Environment.GetFolderPath method, which is used with the Environment.SpecialFolder enum as well as, less commonly, the Environment.SpecialFolderOption enum. It is necessary to include the System namespace to use the Environment type.
.NET Framework Info