MSDN Documentation

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

ConstructorDescription
Value(object value)Initializes a new instance that wraps the specified value.

Methods

MethodReturnsDescription
bool Equals(Value other)boolDetermines whether the current instance is equal to another Value instance.
int CompareTo(Value other)intCompares the current instance with another Value instance.
string ToString()stringReturns a string representation of the wrapped value.

Properties

PropertyTypeDescription
object DataobjectGets the underlying value.
Type DataTypeTypeGets 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

See Also