System.Value Class
Overview
The System.Value
class provides a simple wrapper for primitive values that can be used in generic collections where a reference type is required.
Syntax
public sealed class Value : IEquatable<Value>, IComparable<Value>
{
public Value(object value);
public object Data { get; }
public Type DataType { get; }
// ...
}
Constructors
Constructor | Description |
---|---|
Value(object value) | Initializes a new instance that wraps the specified value . |
Methods
Method | Returns | Description |
---|---|---|
bool Equals(Value other) | bool | Determines whether the current instance is equal to another Value instance. |
int CompareTo(Value other) | int | Compares the current instance with another Value instance. |
string ToString() | string | Returns a string representation of the wrapped value. |
Properties
Property | Type | Description |
---|---|---|
object Data | object | Gets the underlying value. |
Type DataType | Type | Gets the System.Type of the underlying value. |
Fields
This class does not expose public fields.
Remarks
System.Value
is useful when you need to store heterogeneous data in a collection that requires a reference type, such as List<object>
or Dictionary<string, object>
. It provides type information at runtime via the DataType
property.
Example
var values = new List<Value>{
new Value(42),
new Value(3.14),
new Value("Hello World")
};
foreach (var v in values)
{
Console.WriteLine($"{v.DataType.Name}: {v.Data}");
}
// Output:
// Int32: 42
// Double: 3.14
// String: Hello World