There are a number of ways to do this.
The quickest solution is to use
Process.Start("shutdown","/s 0")
;
For managed code, try WMI classes.
E.g.
ManagementClass mcWin32 = new ManagementClass("Win32_OperatingSystem");
Then invoke
Win32Shutdown
and shutdown the system.
You would need certain priveleges to access the method above.
For a solution that uses unmanaged code, try
Shut Down, Restart, Log off or Lock your computer in C#[
^]