hurnhu
hurnhu

Reputation: 936

accessing a method in a dll

okay, so to start with i have set up the references in the project that i am useing the dll in. what i am trying to do is access the method "haha" in my utils dll

code for dll

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace Utils
{
    public class kb
    {
        public class yes {
            public void haha(string yes)
            { 
             int test = Convert.ToInt32(yes);
            }
        }
    }
}

and in the project im trying to access haha in i have just "Utils.kb.yes" but there is no method in that.. all i can do is Utils.kb.yes.equals and Utils.kb.yes.ReferenceEquals.

Upvotes: 0

Views: 71

Answers (2)

Justin Harvey
Justin Harvey

Reputation: 14682

Since haha() is an instance method, you need to create an instance of the Utils.kb.yes class first:

Utils.kb.yes kb = new Utils.kb.yes();
kb.haha("nextproblem");

Or you also can make the method static:

public class yes {
    public static void haha(string yes)
    { 
        int test = Convert.ToInt32(yes);
    }
}

then you can call it like this:

Utils.kb.yes.haha("I am static!");

Upvotes: 6

Rob
Rob

Reputation: 11798

Your classes do not have a constructor, and besides that, you simply CAN'T do much with a class before instantiating an object out of it. So you should reference your dll, and then create a new object first. From within that object, you can then reference your method(s).

Upvotes: 0

Related Questions