Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share variables between projects

Tags:

c#

.net

I have a solution with some projects. One of this projects is the one I've defined as main, also his class has a main Method.

Inside this class, I've defined some properties public and static. What I want to to is access to this properties from other project file. For example:

Project A:

namespace Cobra
{
    public static class Program
    {
        public static int A;
        public static int B;
...

Project B:

namespace Net
{
    public class HttpHandler : IHttpHandler
    {
        ...
        public void ProcessRequest()
        int a =Cobra.Program.A;
        int b =Cobra.Program.B;
...

How can I do this??

EDIT:

If I add Project A as reference in Project B: "Adding this project as a reference, there will be a circular dependency."

Project B contain some other files, so having a reference to Project B in Project A is needed.

like image 607
Manu Avatar asked Nov 21 '11 08:11

Manu


2 Answers

In Project B, Add a reference to Project A and add a using Cobra statement to Project B wherever you want to access something from the Cobra (Project A) namespace.

like image 160
CodeCaster Avatar answered Oct 17 '22 05:10

CodeCaster


You need to add a reference to Project A to project B - right click on the project node in the solution explorer, select references, then projects then Project A.

You will then have access to all the types in Project A.

See this How To on MSDN.

like image 23
Oded Avatar answered Oct 17 '22 06:10

Oded