How-To ...

Add new variable.
Put data into a variable.
Get data from a variable.
Variable<int> v = (Variable<int>)dataSet["var"];
int i = v[new int[] { 0 }]; // gets the value at the index { 0 }
Work with metadata.
Variable v = dataSet["var"];
v.Metadata["Units"] = "m/s";
. . .
string units = (string)v.Metadata["Units"];
Create, modify, and get data from a scalar variable
Zero-rank variables (also called scalar variables) have Variable.Rank equal to zero and contain a single value. The value is represented as a one-dimensional array with a single element.
Note that the Append(Array) method does not support scalars and throws an exception if is invoked for a scalar variable. Another way to put data or get data from scalar variable is to use a typed indexer from the Variable<DataType> class, as in the example below. In all these methods, an origin parameter (if it is required) must be either null, an array of Int32, or a special constant Variable.DefaultIndices.
Variable<double> scalarDbl = ds.AddVariable<double>("scalarDbl");
Assert.IsTrue(scalarDbl.Rank == 0);

// Using PutData and GetData methods:
scalarDbl.PutData(new double[] { Math.PI });
Assert.AreEqual(1, scalarDbl.GetData().Length); // contains only one element
Assert.AreEqual(Math.PI, ((double[])scalarDbl.GetData())[0]); // true

// Using indexer:
scalarDbl[Variable.DefaultIndices] = 2*Math.PI;
Assert.AreEqual(2*Math.PI, scalarDbl[Variable.DefaultIndices]); // true


An alternative way to work with DataSet is described in the topic Imperative API.