Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
3.33/5 (3 votes)
See more:
C#
public class CaseStageTransitionControlModel : ControlModel // *
{
    CaseStageTransitionControlModel x = new CaseStageTransitionControlModel();
}


In the above I'm creating an instance of that class *. It even let me did that. Now I'm trying to access a method of that class. So when i type x, I don't see any intellisense giving me any option to choose.

Why is that?
How can i access that method?

Most of the time i find problem with instantiating an object of a different class in c# why is that too?
Posted
Updated 1-Nov-11 4:17am
v2
Comments
jpratik 1-Nov-11 10:43am    
have a look at Access Specifiers : http://goo.gl/2Oipf

check the access modifiers of your method.. the method should be publicly accessible to be seen in intelicense.

make your methods public, like

C#
public string myMethod(string param1)
{
    //do something...
    return "Hello";
}


notice the public keyword in the start of the method signature.

mark as answer if solves your problem
 
Share this answer
 
v2
an example:

C#
class Program
{

    static void Main()
    {
        CaseStageTransitionControlModel x = new CaseStageTransitionControlModel();
        x.Method();
        

    }
}
public class CaseStageTransitionControlModel : ControlModel // *
{
    public void Method()
    {
        Console.WriteLine("yes sir!");
    }
}
 
Share this answer
 
one way you can do this is to make a new object of your class (SomeClass name = new SomeClass("Construters"); and then call the method like this: name.YourMethodsnamehere(variables here if you need any); BUT REMEMBER you can ONLY do this if you have set the class and method to public otherwise you cant access them from outside their own class.
 
Share this answer
 
This problem is so ordinary in programming:)

Must set your class function to public method by "public" word for access to it!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900