0

I'm creating some scripts and running them in runtime, but I'm compiling them only once(unless the code changes) to avoid "memory leak", since everytime I compile a script it take X Kbs from the memory.

Anyway, I'm trying to find a way to use variables that i can get AND set values to them, because if I so like:

int x = 0;
x += 2;
MessageBox.Show(x.ToString());

It will show me 2 everytime, because it is executing the same code and I want to really set this value to x, but when it executes again it will show me 4,6,8 etc, but for that I need to create that "int x" variable somewhere where I can get it.

I tought about a list of variables and create a method like getvariable(x) and setvariable(x), but this list would need to support all type os variables, int, strings, doubles, etc.

Do you have any idea how I can do that?

Tergiver
  • 14,171
  • 3
  • 41
  • 68
Kyky
  • 63
  • 1
  • 7
  • 3
    You're saying this code is evaluated, at runtime, outside of a object oriented context? Then I guess you can't. If you had a class somewhere, you could put a field to hold your variable. – LightStriker Oct 30 '12 at 20:56
  • 2
    Can you clarify a bit more - specify what you mean by "running them in runtime" and "compiling them only once"? By scripts do you mean console applications, or ...? – goric Oct 30 '12 at 20:58
  • Look up Encapsulation and how to use Properties would be a good place to start in regards to Marc-Ande's comment – MethodMan Oct 30 '12 at 21:01
  • I'm wondering what hardware this is running on where you are concerned about creating a new `int` – Jared Oct 30 '12 at 21:05
  • Calling it right now. This is being run through the dev web service or IIS. EDIT: Ignore that. I read "it will" as "it does". You should write "it should". – Nick Vaccaro Oct 30 '12 at 21:06
  • The int is just an example about a variable that I need to set the value. It's a scripting at runtime, you create the code to execute inside the form, the CSharpCodePRovider compile this code, generate an Assembly and run it, and as I said, I'm compiling it once, so I"m saving this Assembly that it generate and I just run the assembly. And yes, it is a windows form. I tought about a class that I could add as reference but this way how would I be able to create the variables on that? I mean, the variables and the values there will be "custom", every user can create them, they are not default. – Kyky Oct 30 '12 at 21:09

0 Answers0