how to run other classes than main in debug mode


New member
Jan 2, 2017
Programming Experience
Hey all,

Im starting to learn C sharpe. For this im using the book: head first C#
It frustrates me that I cannot seem to run any methods that are in classes other than the void main one
When im testing my code i press on start and it only shows the things with the main void which is the entry point of the program.
Why does this not show the messagebox? how do I call it the right way
what am I doing wrong.

using System;using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Text;

namespace WindowsFormsApplication1
    public static class Program
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
            Application.Run(new Form2());
            Application.Run(new Form1());
        class anotherclass
            public void methode1()
                MessageBox.Show("This is a message", "Message");

Hope some of you can help me out,
already lots of thanks for helping me out on this,

cheers, stephan
You can run any method of any class you want. The Main method is simply the entry point for your application. Your house has a front door, right? Does that stop you going into any room in the house you want? If you want to simply display a message box instead of Form2 and Form1 then delete the code from your Main method that displays Form2 and Form1 and call MessageBox.Show there instead.

Now, you may rail against this but I suggest that you don't waste your time doing so. There are millions of .NET developers the world over and they all happily accept that this is the way it works. It's not a limitation. The Main method is where your app starts. That's it, that's all. Whatever you want your app to do, do it in the Main method or in other methods called from the Main method. Accept that and get on and learn how to do all the many things you can do with C#.
Top Bottom