JackTheRipper JackTheRipper - 2 months ago 13
C# Question

Cannot Access with an Instance Reference

While I can do this:

System.Diagnostics.Process.Start(@"C:\MyFolder\MyProgram.cmd");


I can't do this:

var process = new System.Diagnostics.Process();
process.Start(@"C:\MyFolder\MyProgram.cmd");


Error: Member 'System.Diagnostics.Process.Start(string)' cannot be accessed with an instance reference; qualify it with a type name instead.

What is the reason behind this? Can anyone please explain?

Thanks in advance!

Answer

it's a static method. You can't use it off an instance of Process:

public static Process Start(string fileName)

Use the empty Start() method, that is designed to work off an instance:

Starts (or reuses) the process resource that is specified by the StartInfo property of this Process component and associates it with the component.

Comments