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

前端 未结 6 940
孤独总比滥情好
孤独总比滥情好 2020-12-29 04:51

I am a newbie of C# and MS visual studio, and I want to use the C# class which defined in another file, but can\'t get it work.

Here is the program.cs

6条回答
  •  青春惊慌失措
    2020-12-29 05:05

    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.)

提交回复
热议问题