1

I'm going to try to explain this as best I can. I'm working on an application that needs to get data from another program. I have them all in the same solution I believe, I have the application referencing the .dll that has the variable i want in it. the code is kinda set up like this

the .cs file that has the varible i want is set up like this

public class myObserverClass
{
  //then there is a bunch of functions and the variable i need is in one like this
  static void functionWithMyVariable(ref something, int toTier){
    string myVariable = some value;
  }
}

In my main application i need myVariable but i'm not sure how to access it. I have it using the namespace of the second program.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
dstew
  • 109
  • 1
  • 9

3 Answers3

1

Have your function return the variable value you want rather than returning void.

static string functionWithMyVariable(ref something, int toTier){
  string myVariable = some value;
  return myVariable;
}

Also note that you need to make functions and (object/class level variables) PUBLIC if you want to access them from other projects.

myObserverClass.functionWithMyVariable();

Will not work unless functionWithMyVariable is a PUBLIC function.

public string functionWithMyVariable(ref something, int toTier){
Louis Ricci
  • 20,804
  • 5
  • 48
  • 62
  • Well there are multiple variables that i need from this function is the issue so i can't have it return just one variable. – dstew Jan 02 '13 at 17:42
  • 1
    @user1873594 - That's simple, you have it return a List or List, or Dictionary, or a well defined Results class that contains all the values you want to return. – Louis Ricci Jan 02 '13 at 17:49
0

Referencing an assembly (the .dll) in both applications is having them share code, which is not the same as sharing data. Each program will create individual in-memory versions of the classes and structures found in the .dll. See Transfer large data between .net applications on same computer for more info on how to transfer data between .net apps.

Community
  • 1
  • 1
0

If I am not mistaken you have dll of an application say App1 having Class say C1 which is public. In this class you have a variable say V1. Now you refer this dll into your another application say App2 where you want to access above said variable V2. Now if the class C1 and the variable V1 both are public then you can access these like we access variables of one class to another into a single application by creating its object, but the condition is that both class and variable should be public.

Hope this can help you :)