T GetValue( string name, T defaultValue )

book_4_sparkGenerated
code_blocksInput

Description

The GetValue<T> method in the Sandbox.Package class is used to retrieve a value associated with a specified name. If the value is not found, a default value is returned. This method is virtual, allowing derived classes to override its behavior.

Usage

To use the GetValue<T> method, you need to provide the name of the value you want to retrieve and a default value of type T that will be returned if the specified name does not exist.

Parameters:

  • name (System.String): The name of the value to retrieve.
  • defaultValue (T): The default value to return if the specified name is not found.

Returns: T - The value associated with the specified name, or the default value if the name is not found.

Example

// Example usage of GetValue<T> method
var package = new Package();
string valueName = "exampleKey";
int defaultValue = 42;

// Attempt to get the value associated with 'exampleKey'.
// If not found, it will return the default value of 42.
int result = package.GetValue<int>(valueName, defaultValue);

// Output the result
// result will be either the value associated with 'exampleKey' or 42 if not found.