It's because being that C# runs on the CLR it doesn't have full access to certain areas. Even then sometimes it's just easier to use an existing method written within the operating system. The parameters are used to control how the method is loaded generally.
Here's an example (from a program I'm working atm):
Code:
#region Field Region
//Declare variables
long
_ticksPerSecond = 0,
_previousElapsedTime = 0;
#endregion
#region Properties
/// <summary>
/// Gets the Elapsed Time of the Precise Timer.
/// </summary>
public double ElapsedTime
{
get
{
long time = 0;
double elapsedTime;
QueryPerformanceCounter(ref time);
elapsedTime = (double)(time - _previousElapsedTime) / (double)_ticksPerSecond;
_previousElapsedTime = time;
return elapsedTime;
}
}
#endregion
#region Constructor
/// <summary>
/// Creates a new precise timer.
/// </summary>
public PreciseTimer()
{
QueryPerformanceFrequency(ref _ticksPerSecond);
GetElapsedTime(); // Get rid of first rubbish result
}
#endregion
#region Imported Methods
[SuppressUnmanagedCodeSecurity]
[DllImport("kernel32")]
private static extern bool QueryPerformanceFrequency(ref long PerformanceFrequency);
[SuppressUnmanagedCodeSecurity]
[DllImport("kernel32")]
private static extern bool QueryPerformanceCounter(ref long PerformanceCount);
#endregion
In this example it uses the two methods within the kernel32.dll for windows to get an extremely accurate timer. You could try to use "DateTime" but this could return incorrect results between updates and would result in slower processing. However using this method allows for a great handle for an infinite loop like that found in games or graphics based software.
To find these kinds you could read them all found on msdn, however normally you may just come across more methods through experience and searching for solutions.
Lastly another reason could be that someone wrote the majority of code you need in c++ instead of c#. However it would be faster for you to import the methods instead of creating them in c# again.
MSDN Sources:
[Only registered and activated users can see links. Click Here To Register...]
[Only registered and activated users can see links. Click Here To Register...]