how to call main method in c sharp?

How can I call main method from a method defined in some other class/library?
Ideally with all existing args[].

Thanks in advance.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

you just need to create the instnace of the class and call the metod by passing the arguments reqired.
if you have created a method named TestMethod in side TestClass then you can call it like,
 TestClass objclass = new TestClass();
 objclass.TestMethod("1", "2");

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Main method is the static method. By default with one of following signatures:
static void Main()
static int Main()
static void Main(string[] args)
static int Main(string[] args)

And you don't need class instance for invocation that method.
Try something like this:

Assembly assembly = Assembly.LoadFrom("ConsoleApplication1.exe");
Type type = assembly.GetType("ConsoleApplication1.Program");
string[] parameter = {"arg1", "arg2" };
type.InvokeMember("Main", BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.NonPublic, null, type, new object[] { parameter });

Open in new window

BTW consider using System.Diagnostics.Process for creating instance of other application (one with Maing method):
ProcessStartInfo info = new ProcessStartInfo("ConsoleApplication1.exe", "arg1 arg2");
//info.CreateNoWindow = true;

Open in new window

quasar_eeAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.