Rant Variables in C#

Global variables created by Rant programs can be accessed and manipulated through the Rant API. On this page is a simple example of how to create a Rant variable, read it from your C# code, and then modify it through RantEngine.

Setting a variable in Rant[link]

First, a string variable is created by running the following pattern:

[vs:example;Hello World!]

This can be done with the following C# code:

var rant = new RantEngine();
var pgmSetVar = RantProgram.CompileString(@"[vs:example;Hello World!]");

Another pattern can then be used to retrieve the value of the variable:

var pgmPrintVar = RantProgram.CompileString(@"[v:example]");
// Prints: "Hello World!"

Retrieving the variable in C#[link]

To retrieve the value of the variable in C#, use the RantEngine instance's indexer to retrieve the RantObject instance associated with the variable name.

// Prints: "Hello World!"

Setting the variable in C#[link]

The value of the variable can be changed through the same indexer.

rant["example"] = new RantObject("Hello from C#!");

If you run pgmPrintVar again, you will find that the value of example has changed to "Hello from C#!".