Hello to all, I'm have been porgramming console applicactions in C# to learn the language. Today I was curious in windows forms, and started a project. After searching in the web/youtube I see people putting all the code on the button code(when doubble click), BUT I saw there the same program.cs file that consoles apps have.My questions:

-Where does the code actually goes?code to solve math, connect to database, write something to a txt file etc?
-Shouldn't it go to the program.cs file? In a console app I usually put my code there and depending on the project I create new class files.
-That said, what is the program.cs file for?

I'm I doing this wrong on console applications? Is my first time learning OOP. Please can someone explain this to me?
I'm a bit confused!

Recommended Answers

All 4 Replies

The Program.cs file, contains the Main method. Every program has a starting point, in C# this is Main.
For a console app it is sufficient to do all your coding in Main.
For a Forms project, Main runs a new Forms object, all further action is done in the Form, so alot of coding takes place in the Form1.cs file instead of in Program.cs.
Hope this is a bit clear. If not, ask! We are here to help if we can.

Hello ddanbe thanks for replying and for giving a good explaination, I understood better now how this works.SO for example, I can use the program.cs file or another class file with some methods to do, for example, calculate the perimeter of a square, then call the method on the form, in the button code. My point is, I can create class files to do some "work" then call them, instead of having the same code on the forms code file, because it may become very disorganized I think.

You are right. Make a Perimeter class(or whatever you need) and make an instance of it in the form class, so all your perimeter method code(or other calculations etc.) would not clutter up your Form1 code.

Ok ddanbe I understand now what I have to do, I'm going to pass to windows forms now, because I think what I will learn by programming with forms can be applied to console apps, of course somethings change but not much I think, well depends on the project. I think that it is a good bet to start now with forms.Thank you very much for explaining me this, your explaination helped me alot.

Stay well :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.