How to create an object of any class that is available in the solution
I have a serious question for you guys. I am working on a project that has hundreds of classes. Why cant i access all classes if i want to create an object of that class.
For example: I have Class A, B and C.
In Page 1, i can create an object of A and B but not C. When i try to type in Class C, the intellisense does not work. I need to access class C to get some of the functions used in it. What can i do to get access to create objects of class C??开发者_运维百科
Chances are you're missing either:
- An assembly reference (to the project containing class C)
- A
using
directive for the namespace containing class C
For example, to use the NetworkStream
class, you'd need a reference to the System.dll assembly, and you'd usually have a using directive like this:
using System.Net.Sockets;
in the class that needed to use it. You don't have to have a using
directive - you can specify the full name explicitly - but it's usually a good idea.
Now it's also possible that class C is internal to the project it's part of, and you're in a different project - which means that you don't have access to it (and you're not meant to). Or perhaps you're trying to call a constructor and there aren't any publicly available ones, for example.
This sounds like a namespace issue. You can put classes into unique namespaces to avoid naming conflicts between classes and also to help organize your code. Take a look at each class and determine what namespace it resides in. If they reside in different namespaces you will have to put a using statement at the top of the class your trying to access them from. Also if some of the class reside in physical different projects you will have to reference them as well. Hope this helps.
Enjoy!
Most likely class C doesn't exist within the same assembly or namespace as the other classes. Double check your references and using statements and you will likely find class C will become available to you.
精彩评论