开发者

I made another class in C#, and I put the class in its own file, how do I access the class?

So I have created a Windows Form in C#. I have my form, but I then created another class file, and in turn, another class. Back in the form, I want to be able to access my class (called Test).

I've tried declaring my class by its name:

Test myclass = new Test();

And I've tried simply accessing its method:

Test.Print("helloworld");

However, no matter what I do, I get the error:

The type or namespace name 'Highligh开发者_Go百科ter' does not exist in the namespace 'Syntax_Highlighting' (are you missing an assembly reference?)

So, how do I fix it so I can use my class? My two files share the same namespace (and even adding it as a using directive didn't fix it).


Post your code (and I might edit when you do) but, first blush, your new class is probably not marked public.


  1. The file where the new class is defined, should be registered in the same project you are working on. (If using Visual Studio, the file should appear in the solution explorer).

  2. The file must have a namespace declared. The file where you are using you class (not declaring) must have a "using" with the namespace of the class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜