mlg
mlg

Reputation: 1172

Accessing and updating a variable across projects C#

I have a project having a static and non-static class. I want to access this class variable and update from another project under same solution. How I can do this? [For both static and non-static case]

Upvotes: 1

Views: 2683

Answers (3)

Mahmoud Gamal
Mahmoud Gamal

Reputation: 79929

  • Build the first project.
  • In the second project's references add a reference to the first project.
  • reference the namespace you want to use in your code by Using FirstProject.ns;, then you can use the class you want to access.

Note that: the class you want to use in the second project should has at least an acces modifier public in order to appear in your second project.

Upvotes: 3

KV Prajapati
KV Prajapati

Reputation: 94645

First of all your project must be library type. Make sure that these (classes defined a project) types must be public and it will be good practice to use namespace.

namespace MyCompany
{
   public class Foo {}
}

Upvotes: 0

penartur
penartur

Reputation: 9912

You will need to "Add reference" to your project with the class in your need in your "another project" and make sure your classes you want to use from another project are marked as "public". Then you can use these from your "another project" as usual.

Upvotes: 1

Related Questions