简体   繁体   中英

Namespace or type can't be found

I have a program consisting of three classes. When I put the classes in the same file I can compile and run the code just fine. When I put each class in a separate file I get error CS0246 "The type or namespace could not be found" when I try to make objects of the two non-main method classes. I am not using namespaces, and the files are in the same folder.

I am not using Visual Studio. I compile the code in the command line. (Windows 7).

If you are separating the classes into different files you will need to 'import' the classes with using statements (typically if they have a namespace).

Try implementing using statements with just the class names, else I would highly recommend using namespaces (the same namespace is preferable in this scenario) in conjunction with using statements

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM