Click here to Skip to main content
15,890,336 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How to call a class method from another class without using a dot operator,this keyword and Reflection in C#.net ?
Posted
Updated 21-Feb-12 18:28pm
v2
Comments
krumia 22-Feb-12 0:54am    
Can you state the reasons for NOT using these functionality provided by default by the language?
Gireeshk1 6-Mar-12 23:02pm    
It is a project specific requirement, needs to call these methods in an editor without dot.
Mohammad A Rahman 22-Feb-12 2:27am    
Is both assembly written using C# or {Com, C#} or { C++, C# }?
Gireeshk1 6-Mar-12 23:02pm    
Yes, Both in c#.

Just call your method inside the method you going to use inside of your class. Or you can use the this keyword and it will show all the classes members.
http://msdn.microsoft.com/en-us/library/dk1507sz%28v=vs.100%29.aspx[^]
 
Share this answer
 
Comments
Gireeshk1 22-Feb-12 0:33am    
I need to call these methods from another class library and need to use only the function name(Without using dot operator).
krumia 22-Feb-12 0:53am    
And please tell me why do you NOT want to use the DOT?
Gireeshk1 25-Feb-12 12:18pm    
It is a project specific requirement,
needs to call these methods in an editor without dot.
Dot is not an operator.

Well, dot is a lexical element used, among other things, to qualify a member of a type with a reference of an instance which is used as a "this" parameter for instance (non-static) methods or properties or as a class name in case of static members. As in a body of an instance (non-static) method "this" is assumed, "this." can be omitted, which gives you a call or an access to a member without dot. For static members, a declaring class is assumed, so class name with a dot could be used.

That is:
C#
class MyClass {

    void InstanceMethod(/* "this" is passed implicitly */) {
        //working with instance members:
        a = 1; // this.a assumed
        this.b = 2;
        MethodA(/*"this" passed */); //this.Method A assumed
        this.MethodB();
        //
        //working with static members:
        c = 3; //MyClass.c assumed
        MyClass.d = 4;
        MethodC(); //MyClass.MethodC assumed
        MyClass.MethodD();
    } //InstanceMethod

    static void StaticMethod() {
        //working with instance members would not compile;
        //instance is not known (no "this"):
        /*
        a = 1; // this.a assumed
        this.b = 2;
        MethodA(/*"this" passed */); //this.Method A assumed
        this.MethodB();
        */
        //
        //working with static members is only allowed:
        c = 3; //MyClass.c assumed
        MyClass.d = 4;
        MethodC(); //MyClass.MethodC assumed
        MyClass.MethodD();
    } //InstanceMethod

    //instance members:
    int a, b;
    void MethodA() {/*...*/}
    void MethodB() {/*...*/}

    //static members:
    static int c, d;
    static void MethodC() {/*...*/}
    static void MethodD() {/*...*/}

    //...

} //class MyClass


See also my past answer:
What makes static methods accessible?[^].

—SA
 
Share this answer
 
v5
Comments
Gireeshk1 22-Feb-12 0:32am    
First of all thank you for your answer. But I need to call these methods from another class library and need to use only the function name(Without using dot operator).
C#
var type = typeof(TestClass);
var method = type.GetMethod("Print");
method.Invoke(null,null);


C#
public class TestClass
{
    public static void Print()
    {
        Debug.Write("### Print Method Invoked");
    }
}
 
Share this answer
 
Comments
Gireeshk1 22-Feb-12 0:32am    
I can not use reflection and dot operator......

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