user2545071
user2545071

Reputation: 1410

How to get access to class at another assembly via c#?

I have solution and my class in it. Then i add another project at my solution. So, i want to use another class B and its methods,field from my class A.

Class B looks like:

class B
{
public int field1;
public int field2;
    public void Test() {}
}

How to get access from A class to fields B?And how to create object B? I try to :

using Another.Project;

But, i cannot see that class. Should i use reflection?or something else?

Or i have to copy this class to my project and reimplement him? I dont want to do this,because class B have access to another classes and it implementation is difficult. Class B is not my class and i cannot modify it. Thank you!

P.S. i add reference and type using ... ,but i have error- class B inaccesible due to its protection level.

Upvotes: 3

Views: 2522

Answers (3)

Michael Mairegger
Michael Mairegger

Reputation: 7301

Right Click the Project Folder, click Add Reference and select the project where B is located.

Additionally you should declare the class B as public, without any modifier the class is internal, this means that is only visible to the project where the class have been defined.

Upvotes: 2

schei1
schei1

Reputation: 2487

You need to add a reference to Project B from Project A. Then you can add the using Another.Project in a class residing in Project A.

Expand Project A, locate "References", right click and select "Add reference". Check the solution tab in the new window, and select your preferred project.

This however requires the classes you want to use from Project B in Project A to be either public or protected (if you want to subclass it).

Upvotes: 1

germi
germi

Reputation: 4658

You need to add a reference to your other project via "Add reference..." in your project.

Upvotes: 1

Related Questions