Working with Data
h5 provides seamless integration between standard .NET data types and JavaScript primitives.
Primitive Types
Most C# primitive types map directly to JavaScript primitives:
| C# Type | JavaScript Type | Notes |
|---|---|---|
string |
string |
UTF-16 strings |
bool |
boolean |
true / false |
byte, sbyte |
number |
Integer |
short, ushort |
number |
Integer |
int, uint |
number |
Integer |
long, ulong |
number |
Uses BigInt or library emulation depending on config |
float, double |
number |
IEEE 754 floating point |
decimal |
number |
Warning: Precision loss possible if mapped to number |
char |
number |
UTF-16 code unit |
Integers & Floating Point
JavaScript uses 64-bit floating point numbers for all numeric types by default. h5 handles integer arithmetic correctly, including overflow/underflow behavior (configurable via overflowMode).
However, for long (64-bit integer), h5 can use BigInt if supported by the target environment, or a custom Long implementation.
Arrays
C# arrays are mapped to JavaScript arrays.
int[] numbers = new int[] { 1, 2, 3 };
Becomes:
var numbers = [1, 2, 3];
You can use standard array methods and indexers. However, note that C# arrays are fixed-size, while JavaScript arrays are dynamic. h5 enforces C# semantics where possible.
Collections
h5 includes implementations of standard generic collections like List<T>, Dictionary<TKey, TValue>, HashSet<T>, etc.
var list = new List<string> { "a", "b" };
list.Add("c");
var dict = new Dictionary<string, int>();
dict["key"] = 123;
These behave exactly as you expect from .NET, including proper equality comparison for keys in dictionaries.
DateTime
System.DateTime is supported and backed by JavaScript's Date object, but provides the full .NET API surface including time zones and formatting.