# Customize Function

## Customize functions in C#

Add customize function to extend control:

grid.Srm["sqrt"] = new NativeFunctionObject("sqrt", (ctx, owner, args) =>
{
if (args.Length < 1)
return NaNValue.Value;
else
return Math.Sqrt(ScriptRunningMachine.GetDoubleValue(args[0], 0));
});

Test:

grid[2, 1] = "=sqrt(400)";

View its formula:

*Customize function is also can used in script.*
## Customize functions in Script

Object 'script' is the global object which is available in both formula and script. (same as 'window' in JavaScript)

Run the code above once and use it in formula.

Press 'enter':

## Run Script to add functions in C#

It is also possible to run the script to create functions in C#: (eg. lambda function)

grid.RunScript("script.myfunc = data => '[' + data + ']';");