Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access method in class library

Tags:

c#

asp.net

I've moved a class in my project into a class Library in the same solution. I've added a reference in the web project to the class library.

How do I access the methods in the class library?

like image 772
Joshua Slocum Avatar asked Sep 25 '26 10:09

Joshua Slocum


1 Answers

Make sure the method and class are public and instantiate to use it:

YourClass yourClass = new YourClass();
yourClass.YourMethod();

Or, if your method is static:

YourClass.YourMethod();

Make sure to include the namespace of your class is your target classes using statements, i.e.

using ClassLibrary;

If you're unsure of the namespace of YourClass you can find it within the Class file at the top, directly beneath your using statements. Or you can mouse over the YourClass text in the Visual Studios Editor and then select the namespace by clicking the button that appears.

like image 62
djdd87 Avatar answered Sep 28 '26 01:09

djdd87