How to use class from other files in C# with visual studio?

According to your explanation you haven’t included your Class2.cs in your project. You have just created the required Class file but haven’t included that in the project.

The Class2.cs was created with [File] -> [New] -> [File] -> [C# class] and saved in the same folder where program.cs lives.

Do the following to overcome this,

Simply Right click on your project then -> [Add] – > [Existing Item…] : Select Class2.cs and press OK

Problem should be solved now.

Furthermore, when adding new classes use this procedure,

Right click on project -> [Add] -> Select Required Item (ex – A class, Form etc.)

Leave a Comment