C# conformance

C# that behaves like .NET in the browser

Every case below is a piece of C# run twice: on .NET, and as the JavaScript WebSharper compiles it to. The results are compared character by character. Where they differ, it is listed as a known difference, with what to write instead.

WebSharper 11 · core 24cff94d 339 cases in 8 areas as of 2026-11-25

Same result as .NET

95.0%

322 of 339 cases

Known differences

17

where JavaScript itself differs, each with an alternative

Unexplained differences

0

silent mismatches; 0 cases rejected at compile time

Known differences

WebSharper implements a .NET API in JavaScript when it can follow .NET semantics exactly or very closely. It doesn't when that would bloat small, readable output just for coverage, or when only a partial imitation is possible, such as System.Type, which cannot tell apart .NET types that share a JavaScript representation. Those cases are listed here, each with the C# or JavaScript API to use instead.

string.equality.refStrings and formatting

JavaScript strings are values: two equal strings are never different references.

Instead:Compare strings with == or string.Equals.

The case
{ var a = "ab"; var b = string.Concat("a", "b"); return B(a == b) + "," + B((object)a == (object)b) + "," + B(a.Equals(b)); }
.NETtrue,false,true
JStrue,true,true
boxing.equalityTypes and dates

Values are not boxed in JavaScript: two boxed equal numbers compare equal by reference too.

Instead:Compare unboxed values instead of relying on reference identity.

The case
{ object a = 1, b = 1; return B(a == b) + "," + B(a.Equals(b)) + "," + B(Equals(a, b)); }
.NETfalse,true,true
JStrue,true,true
float.precisionNumbers

float is a JavaScript number, so it keeps double precision instead of rounding to single.

Instead:Use double, or a Float32Array from WebSharper.JavaScript when single-precision storage matters.

The case
{ float f = 0.1f; return $"{f}|{(double)f}"; }
.NET0.1|0.10000000149011612
JS0.1|0.1
array.outofrangeCollections

Array accesses are not bounds-checked: reading past the end gives undefined instead of throwing IndexOutOfRangeException.

Instead:Check Length before indexing.

The case
{ var a = new int[2]; return $"{a[2]}"; }
.NETEXN IndexOutOfRange
JSundefined
exception.null.derefLanguage

Dereferencing null throws a JavaScript TypeError, not a NullReferenceException.

Instead:Check for null (or use ?.) instead of catching NullReferenceException.

The case
{ string s = null; return $"{s.Length}"; }
.NETEXN NullReference
JSEXN Exception
dict.insertion.orderCollections

After a Remove, .NET reuses the freed slot for the next Add; that order is unspecified in .NET, and JavaScript keeps insertion order.

Instead:Sort the keys, or use SortedDictionary, when order matters.

The case
{ var d = new Dictionary<string, int> { ["b"] = 1, ["a"] = 2, ["c"] = 3 }; d.Remove("a"); d["d"] = 4; return J(d.Keys); }
.NET[b,d,c]
JS[b,c,d]
generic.defaultTypes and dates

Generics are erased: default(T) inside generic code is null for value types too.

Instead:Pass the default value in, or constrain T to a class.

The case
$"{Box<int>.Default()}|{Box<string>.Default() ?? "null"}"
.NET0|null
JSnull|null
enum.getvaluesPattern matching

Enums are erased to numbers: a boxed or generic enum value formats as its number.

Instead:Call ToString on the statically typed enum value.

The case
J(Enum.GetValues<Color>())
.NET[Red,Green,Blue]
JS[0,5,6]
list.capacity.tostringCollections

No runtime type names: Object.ToString on a type that does not override it does not give the .NET type name.

Instead:Override ToString, or use nameof.

The case
new List<int>().ToString()
.NETSystem.Collections.Generic.List`1[System.Int32]
JS""
object.tostring.defaultTypes and dates

No runtime type names: Object.ToString on a type that does not override it does not give the .NET type name.

Instead:Override ToString, or use nameof.

The case
new Plain().ToString()
.NETConformance.Plain
JS[object Object]
gettype.nameTypes and dates

No reflection: GetType() is not available in JavaScript.

Instead:Use nameof for names, pattern matching (is) for type tests, or WebSharper.JavaScript.Object.GetPrototypeOf for the JavaScript prototype.

The case
new Dog().GetType().Name
.NETDog
JScompile error: not supported
span.sumCollections

Span<T> and stackalloc are not supported.

Instead:Use arrays, or JavaScript typed arrays from WebSharper.JavaScript.

The case
{ Span<int> s = stackalloc int[] { 1, 2, 3 }; var t = 0; foreach (var x in s) t += x; return $"{t}"; }
.NET6
JScompile error: not supported
datetime.isoTypes and dates

A DateTime has no Kind in JavaScript: the "o" format writes local time with its offset, never "Z".

Instead:Use DateTimeOffset, or Date.toISOString from WebSharper.JavaScript for a UTC timestamp.

The case
new DateTime(2024, 7, 4, 9, 3, 0, DateTimeKind.Utc).ToString("o")
.NET2024-07-04T09:03:00.0000000Z
JS2024-07-04T11:03:00.0000000+02:00
readonly.wrapperCollections

AsReadOnly returns a snapshot, not a live wrapper: it doesn't see later changes to the list.

Instead:Call AsReadOnly again after changing the list, or pass the list as IReadOnlyList<T>.

The case
{ var l = new List<int> { 1 }; var r = l.AsReadOnly(); l.Add(2); return $"{r.Count}"; }
.NET2
JS1
sorteddictionary.keys.liveCollections

SortedDictionary.Keys and .Values are snapshots, not live views: they don't see later changes.

Instead:Read Keys/Values again after changing the dictionary.

The case
{ var d = new SortedDictionary<int, string> { [1] = "a" }; var keys = d.Keys; d[2] = "b"; return $"{keys.Count}"; }
.NET2
JS1
typeof.nameTypes and dates

No reflection: System.Type is not available in JavaScript, and a partial typeof(T).Name would suggest otherwise.

Instead:Use nameof(T) for names, or WebSharper.JavaScript.Object.GetPrototypeOf for the JavaScript prototype.

The case
typeof(Dog).Name + "|" + typeof(List<int>).Name
.NETDog|List`1
JScompile error: not supported
typeof.fullnameTypes and dates

No reflection: System.Type is not available in JavaScript, and a partial typeof(T).Name would suggest otherwise.

Instead:Use nameof(T) for names, or WebSharper.JavaScript.Object.GetPrototypeOf for the JavaScript prototype.

The case
typeof(Dog).FullName + "|" + typeof(Dog).Namespace + "|" + typeof(string).FullName + "|" + typeof(Dictionary<string, int>).Name
.NETConformance.Dog|Conformance|System.String|Dictionary`2
JScompile error: not supported

Every case

Each row is the C# that runs and the output .NET prints; a passing case prints exactly the same in JavaScript.

Numbers50 / 51 same as .NET
  • Same result as .NET: int.overflow.wraps
    $"{Big() + 1}"
    -2147483648
  • Same result as .NET: int.multiply.wraps
    $"{Big() * 2}"
    -2
  • Same result as .NET: int.multiply.large
    { int x = (1 << 28) + 1; uint u = uint.MaxValue; return $"{x * x},{u * u},{x * x * x}"; }
    536870913,1,805306369
  • Same result as .NET: int.division.truncates
    $"{-7 / 2},{7 / -2}"
    -3,-3
  • Same result as .NET: int.remainder.sign
    $"{-7 % 3},{7 % -3}"
    -1,1
  • Same result as .NET: int.divide.by.zero
    $"{1 / Zero()}"
    EXN DivideByZero
  • Same result as .NET: int.checked.overflow
    $"{checked(Big() + 1)}"
    EXN Overflow
  • Same result as .NET: uint.wraps
    { uint u = 0; u--; return $"{u}"; }
    4294967295
  • Same result as .NET: byte.wraps
    { byte b = 255; b++; return $"{b}"; }
    0
  • Same result as .NET: short.cast.truncates
    $"{unchecked((short)70000)}"
    4464
  • Same result as .NET: long.max
    $"{BigL()}"
    9223372036854775807
  • Same result as .NET: long.overflow.wraps
    $"{BigL() + 1}"
    -9223372036854775808
  • Same result as .NET: long.multiply
    $"{3_000_000_000L * 3}"
    9000000000
  • Same result as .NET: double.tostring
    $"{0.1 + 0.2}|{1.0}|{1e21}|{1.5e-7}|{double.NaN}|{1.0 / 0}"
    0.30000000000000004|1|1E+21|1.5E-07|NaN|Infinity
  • Same result as .NET: double.to.int.truncates
    $"{(int)2.9},{(int)-2.9}"
    2,-2
  • Same result as .NET: double.to.int.nan
    { double n = double.NaN; return $"{(int)n}"; }
    0
  • Same result as .NET: math.round.bankers
    $"{Math.Round(2.5)},{Math.Round(3.5)},{Math.Round(-2.5)}"
    2,4,-2
  • Same result as .NET: math.round.digits
    $"{Math.Round(1.005, 2)},{Math.Round(2.345, 2)}"
    1,2.35
  • Same result as .NET: math.round.awayfromzero
    $"{Math.Round(2.5, MidpointRounding.AwayFromZero)}"
    3
  • Same result as .NET: math.floor.ceiling
    $"{Math.Floor(-1.5)},{Math.Ceiling(-1.5)},{Math.Truncate(-1.5)}"
    -2,-1,-1
  • Same result as .NET: math.clamp.sign
    $"{Math.Clamp(15, 0, 10)},{Math.Sign(-3.2)},{Math.Abs(-4)}"
    10,-1,4
  • Same result as .NET: math.max.min.int
    $"{Math.Max(3, 7)},{Math.Min(3L, 7L)}"
    7,3
  • Same result as .NET: format.N2
    (1234567.891).ToString("N2")
    1,234,567.89
  • Same result as .NET: format.F3
    (3.14159).ToString("F3")
    3.142
  • Same result as .NET: format.P1
    (0.256).ToString("P1")
    25.6 %
  • Same result as .NET: format.D5
    42.ToString("D5")
    00042
  • Same result as .NET: format.X
    255.ToString("X") + "," + 255.ToString("x4")
    FF,00ff
  • Same result as .NET: format.E2
    12345.678.ToString("E2")
    1.23E+004
  • Same result as .NET: format.interp.align
    $"[{42,5}][{42,-5}]"
    [ 42][42 ]
  • Same result as .NET: format.interp.spec
    $"{3.14159:F2}|{0.5:P0}|{1234:N0}"
    3.14|50 %|1,234
  • Same result as .NET: format.custom
    (1234.5).ToString("0,0.00") + "|" + (0.5).ToString("#.##")
    1,234.50|.5
  • Same result as .NET: string.format
    string.Format("{0}-{1:F1}-{0}", 1, 2.25)
    1-2.2-1
  • Same result as .NET: parse.int
    $"{int.Parse("42")},{int.Parse(" -7 ")}"
    42,-7
  • Same result as .NET: parse.int.invalid
    $"{int.Parse("4x2")}"
    EXN Format
  • Same result as .NET: parse.int.overflow
    $"{int.Parse("99999999999")}"
    EXN Overflow
  • Same result as .NET: tryparse.int
    { var ok = int.TryParse("12a", out var v); return $"{B(ok)},{v}"; }
    false,0
  • Same result as .NET: parse.double
    $"{double.Parse("1.5e3", CultureInfo.InvariantCulture)}"
    1500
  • Same result as .NET: tryparse.double
    { var ok = double.TryParse("abc", out var v); return $"{B(ok)},{v}"; }
    false,0
  • Same result as .NET: convert.toint32.rounds
    $"{Convert.ToInt32(2.5)},{Convert.ToInt32(3.5)}"
    2,4
  • Same result as .NET: int.tostring.negative.zero
    $"{-0.0}"
    -0
  • Same result as .NET: char.arith
    { char c = 'a'; c++; return $"{c},{(int)'A'},{(char)66}"; }
    b,65,B
  • Same result as .NET: char.isdigit.letter
    $"{B(char.IsDigit('7'))},{B(char.IsLetter('7'))},{B(char.IsWhiteSpace('\t'))},{B(char.IsUpper('Q'))}"
    true,false,true,true
  • Same result as .NET: bitwise.shift
    $"{1 << 33},{-16 >> 2},{-16 >>> 2},{1L << 40}"
    2,-4,1073741820,1099511627776
  • Same result as .NET: bitwise.ops
    $"{6 & 3},{6 | 3},{6 ^ 3},{~5}"
    2,7,5,-6
  • Same result as .NET: compound.assign.ops
    { int x = 10; x += 5; x *= 2; x -= 3; x /= 4; x %= 4; x <<= 2; return $"{x}"; }
    8
  • Same result as .NET: nullable.arith
    { int? a = null; int? b = 3; return $"{a + b}|{(a ?? 0) + b}|{B((a + b).HasValue)}"; }
    |3|false
  • Same result as .NET: nullable.compare
    { int? a = null; return $"{B(a < 3)},{B(a == null)},{B(a >= 3)}"; }
    false,true,false
  • Same result as .NET: int.minvalue.negate
    { int m = int.MinValue; return $"{-m}"; }
    -2147483648
  • Same result as .NET: double.equality.nan
    $"{B(double.NaN == double.NaN)},{B(double.NaN.Equals(double.NaN))}"
    false,true
  • Known difference: float.precision
    { float f = 0.1f; return $"{f}|{(double)f}"; }
    .NET0.1|0.10000000149011612
    JS0.1|0.1
  • Same result as .NET: int.compareto
    $"{3.CompareTo(5)},{5.CompareTo(5)}," + "b".CompareTo("a")
    -1,0,1
Strings and formatting47 / 48 same as .NET
  • Same result as .NET: split.basic
    J("a,b,,c".Split(','))
    [a,b,,c]
  • Same result as .NET: split.removeempty
    J("a,b,,c".Split(',', StringSplitOptions.RemoveEmptyEntries))
    [a,b,c]
  • Same result as .NET: split.trimentries
    J(" a , b ,c ".Split(',', StringSplitOptions.TrimEntries))
    [a,b,c]
  • Same result as .NET: split.chars
    J("a b;c".Split(new[] { ' ', ';' }))
    [a,b,c]
  • Same result as .NET: split.string
    J("a::b::c".Split("::"))
    [a,b,c]
  • Same result as .NET: split.count
    J("a,b,c,d".Split(',', 2))
    [a,b,c,d]
  • Same result as .NET: trim.chars
    "xxhixx".Trim('x') + "|" + " hi ".TrimStart() + "|" + " hi ".TrimEnd() + "|"
    hi|hi | hi|
  • Same result as .NET: pad
    "7".PadLeft(3, '0') + "|" + "ab".PadRight(4) + "|"
    007|ab |
  • Same result as .NET: substring
    "hello".Substring(1, 3) + "|" + "hello".Substring(2)
    ell|llo
  • Same result as .NET: substring.outofrange
    "hello".Substring(3, 5)
    EXN ArgumentOutOfRange
  • Same result as .NET: indexof
    $"{"hello".IndexOf('l')},{"hello".LastIndexOf('l')},{"hello".IndexOf("lo")},{"hello".IndexOf('z')}"
    2,3,3,-1
  • Same result as .NET: indexof.startindex
    $"{"abcabc".IndexOf('b', 2)}"
    4
  • Same result as .NET: contains.comparison
    B("Hello".Contains("hell", StringComparison.OrdinalIgnoreCase))
    true
  • Same result as .NET: startswith.endswith
    $"{B("Hello".StartsWith("He"))},{B("Hello".EndsWith("LO", StringComparison.OrdinalIgnoreCase))}"
    true,true
  • Same result as .NET: equals.ignorecase
    B(string.Equals("abc", "ABC", StringComparison.OrdinalIgnoreCase))
    true
  • Same result as .NET: compare.ordinal
    $"{Math.Sign(string.CompareOrdinal("a", "B"))},{Math.Sign(string.Compare("a", "b"))}"
    1,-1
  • Same result as .NET: upper.lower.invariant
    "MiXeD".ToUpperInvariant() + "|" + "MiXeD".ToLowerInvariant()
    MIXED|mixed
  • Same result as .NET: replace
    "a-b-c".Replace("-", "+") + "|" + "a-b-c".Replace('-', '_')
    a+b+c|a_b_c
  • Same result as .NET: insert.remove
    "hello".Insert(2, "XX") + "|" + "hello".Remove(1, 2) + "|" + "hello".Remove(3)
    heXXllo|hlo|hel
  • Same result as .NET: join.concat
    string.Join("-", new[] { 1, 2, 3 }) + "|" + string.Concat("a", 1, true)
    1-2-3|a1True
  • Same result as .NET: join.null
    string.Join(",", new string[] { "a", null, "b" })
    a,,b
  • Same result as .NET: join.concat.objects
    string.Join(",", 1, false, null, 2.5) + "|" + string.Concat(new object[] { true, null, -0.0, 7 }) + "|" + string.Concat(false, "x")
    1,False,,2.5|True-07|Falsex
  • Same result as .NET: isnullorwhitespace
    $"{B(string.IsNullOrWhiteSpace(" \t"))},{B(string.IsNullOrEmpty(""))}"
    true,true
  • Same result as .NET: char.indexer
    { var s = "abc"; return $"{s[1]},{s[^1]}"; }
    b,c
  • Same result as .NET: string.range
    "hello world"[6..] + "|" + "hello"[1..^1]
    world|ell
  • Same result as .NET: string.ctor.repeat
    new string('=', 5)
    =====
  • Same result as .NET: tochararray.reverse
    new string("hello".ToCharArray().Reverse().ToArray())
    olleh
  • Known difference: string.equality.ref
    { var a = "ab"; var b = string.Concat("a", "b"); return B(a == b) + "," + B((object)a == (object)b) + "," + B(a.Equals(b)); }
    .NETtrue,false,true
    JStrue,true,true
  • Same result as .NET: stringbuilder
    { var sb = new StringBuilder(); sb.Append("a").Append(1).AppendLine("b").Append('c'); sb.Insert(0, ">"); return sb.ToString().Replace("\n", "\\n").Replace("\r", "\\r") + "|" + sb.Length; }
    >a1b\nc|6
  • Same result as .NET: stringbuilder.remove.replace
    { var sb = new StringBuilder("hello world"); sb.Remove(0, 6).Replace('o', '0'); return sb.ToString(); }
    w0rld
  • Same result as .NET: interp.nested
    { var xs = new[] { 1, 2 }; return $"{xs.Length} items: {string.Join(";", xs.Select(x => $"<{x}>"))}"; }
    2 items: <1>;<2>
  • Same result as .NET: interp.null
    { string s = null; object o = null; return $"[{s}][{o}]"; }
    [][]
  • Same result as .NET: interp.adjacent.numbers
    { int a = 1, b = 2; return $"{a}{b}"; }
    12
  • Same result as .NET: interp.single.number.is.string
    { object o = $"{7}"; return B(o is string); }
    true
  • Same result as .NET: interp.bool
    $"{true}|{false}"
    True|False
  • Same result as .NET: raw.literal
    """a "quoted" {x}"""
    a "quoted" {x}
  • Same result as .NET: verbatim
    @"c:\path\""q"""
    c:\path\"q"
  • Same result as .NET: escape.unicode
    "\u00e9\t|".Length.ToString()
    3
  • Same result as .NET: char.tostring.concat
    'a' + "b" + 'c'
    abc
  • Same result as .NET: char.plus.char
    $"{'a' + 'b'}"
    195
  • Same result as .NET: format.string.braces
    string.Format("{{{0}}}", 5)
    {5}
  • Same result as .NET: string.compareto.culture
    $"{Math.Sign("apple".CompareTo("Banana"))}"
    1
  • Same result as .NET: tostring.object.null
    { object o = null; return o?.ToString() ?? "null"; }
    null
  • Same result as .NET: string.split.empty
    $"{"".Split(',').Length}"
    1
  • Same result as .NET: trim.unicode.ws
    $"[{"\u00a0x\u00a0".Trim()}]"
    [x]
  • Same result as .NET: lastindexof.string
    $"{"a.b.c".LastIndexOf(".")}"
    3
  • Same result as .NET: string.contains.char
    B("abc".Contains('b'))
    true
  • Same result as .NET: string.equals.null
    { string s = null; return B(s == null) + "," + B("a" != null); }
    true,true
Collections46 / 52 same as .NET
  • Same result as .NET: list.ops
    { var l = new List<int> { 3, 1, 2 }; l.Add(5); l.Insert(0, 9); l.Remove(1); l.RemoveAt(1); return J(l) + l.Count; }
    [9,2,5]3
  • Same result as .NET: list.sort.default
    { var l = new List<int> { 10, 9, 1, 100 }; l.Sort(); return J(l); }
    [1,9,10,100]
  • Same result as .NET: list.sort.strings
    { var l = new List<string> { "b", "B", "a", "A" }; l.Sort(StringComparer.Ordinal); return J(l); }
    [A,B,a,b]
  • Same result as .NET: list.sort.comparison
    { var l = new List<int> { 1, 3, 2 }; l.Sort((a, b) => b.CompareTo(a)); return J(l); }
    [3,2,1]
  • Same result as .NET: list.removeall.findindex
    { var l = new List<int> { 1, 2, 3, 4, 5 }; var n = l.RemoveAll(x => x % 2 == 0); return $"{n},{J(l)},{l.FindIndex(x => x > 1)}"; }
    2,[1,3,5],1
  • Same result as .NET: list.indexer.outofrange
    { var l = new List<int> { 1 }; return $"{l[5]}"; }
    EXN ArgumentOutOfRange
  • Same result as .NET: list.getrange.reverse
    { var l = new List<int> { 1, 2, 3, 4 }; l.Reverse(); return J(l.GetRange(1, 2)); }
    [3,2]
  • Same result as .NET: list.binarysearch
    $"{new List<int> { 1, 3, 5, 7 }.BinarySearch(5)},{new List<int> { 1, 3, 5, 7 }.BinarySearch(4)}"
    2,-3
  • Same result as .NET: list.modify.during.foreach
    { var l = new List<int> { 1, 2 }; foreach (var x in l) l.Add(x); return "no exn"; }
    EXN InvalidOperation
  • Known difference: array.outofrange
    { var a = new int[2]; return $"{a[2]}"; }
    .NETEXN IndexOutOfRange
    JSundefined
  • Same result as .NET: array.default.values
    J(new int[3]) + "|" + J(new string[2].Select(s => s ?? "null")) + "|" + J(new bool[2].Select(B))
    [0,0,0]|[null,null]|[false,false]
  • Same result as .NET: array.sort.reverse
    { var a = new[] { 3, 1, 2 }; Array.Sort(a); Array.Reverse(a); return J(a); }
    [3,2,1]
  • Same result as .NET: array.resize.copy
    { var a = new[] { 1, 2 }; Array.Resize(ref a, 4); var b = new int[4]; Array.Copy(a, b, 2); return J(a) + J(b); }
    [1,2,0,0][1,2,0,0]
  • Same result as .NET: array.2d
    { var m = new int[2, 3]; m[1, 2] = 5; return $"{m.GetLength(0)},{m.GetLength(1)},{m[1, 2]},{m.Length}"; }
    2,3,5,6
  • Same result as .NET: array.2d.init
    { var m = new[,] { { 1, 2, 3 }, { 4, 5, 6 } }; m[0, 1] += 10; return $"{m.Rank},{m.GetLength(0)},{m.GetLength(1)},{m.Length},{m[0, 1]},{m[1, 2]},{m.GetUpperBound(1)}"; }
    2,2,3,6,12,6,2
  • Same result as .NET: array.2d.defaults
    { var s = new string[2, 2]; var b = new bool[1, 2]; return $"{B(s[1, 1] == null)},{B(b[0, 1])}"; }
    true,false
  • Same result as .NET: array.2d.declaration
    { int[,] m = { { 1, 2 }, { 3, 4 } }; var n = new int[2, 2] { { 5, 6 }, { 7, 8 } }; return $"{m.GetLength(1)},{m[1, 0]},{n.Length},{n[1, 1]}"; }
    2,3,4,8
  • Same result as .NET: array.jagged
    { var j = new int[2][]; j[0] = new[] { 1 }; j[1] = new[] { 2, 3 }; return $"{j[1][1]},{j.Sum(r => r.Length)}"; }
    3,3
  • Same result as .NET: array.equality.ref
    B(new[] { 1 }.Equals(new[] { 1 })) + "," + B(new[] { 1 }.SequenceEqual(new[] { 1 }))
    false,true
  • Same result as .NET: array.fill.indexof
    { var a = new int[3]; Array.Fill(a, 7); return $"{J(a)},{Array.IndexOf(a, 7)},{Array.IndexOf(a, 8)}"; }
    [7,7,7],0,-1
  • Same result as .NET: array.range.slice
    J(new[] { 1, 2, 3, 4, 5 }[1..^1]) + J(new[] { 1, 2, 3 }[^2..])
    [2,3,4][2,3]
  • Same result as .NET: array.covariance
    { object[] o = new string[] { "a" }; return $"{o[0]}"; }
    a
  • Known difference: dict.insertion.order
    { var d = new Dictionary<string, int> { ["b"] = 1, ["a"] = 2, ["c"] = 3 }; d.Remove("a"); d["d"] = 4; return J(d.Keys); }
    .NET[b,d,c]
    JS[b,c,d]
  • Same result as .NET: dict.int.keys.order
    { var d = new Dictionary<int, string> { [10] = "a", [2] = "b", [1] = "c" }; return J(d.Keys); }
    [10,2,1]
  • Same result as .NET: dict.negative.keys.order
    { var d = new Dictionary<int, int> { [5] = 0, [-3] = 0, [0] = 0, [-1] = 0 }; return J(d.Keys) + J(new HashSet<int> { 9, -2, 4 }); }
    [5,-3,0,-1][9,-2,4]
  • Same result as .NET: dict.trygetvalue.defaults
    { var d = new Dictionary<string, bool>(); var e = new Dictionary<string, double>(); d.TryGetValue("x", out var b); e.TryGetValue("x", out var x); return $"{B(b)},{x}"; }
    false,0
  • Same result as .NET: dict.comparer.ordinal
    { var d = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase) { ["a"] = 1 }; d["A"] = 2; var h = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "x", "X", "y" }; return $"{d.Count},{d["a"]},{h.Count},{StringComparer.Ordinal.Compare("a", "B")},{StringComparer.OrdinalIgnoreCase.Equals("ab", "AB")}"; }
    1,2,2,31,True
  • Same result as .NET: sorteddictionary.ops
    { var d = new SortedDictionary<int, string>(Comparer<int>.Create((a, b) => b.CompareTo(a))) { [1] = "a", [3] = "c", [2] = "b" }; d.Remove(3); return J(d.Keys) + J(d.Values) + $"{d.Count},{B(d.ContainsKey(2))},{B(d.TryGetValue(9, out var v))}"; }
    [2,1][b,a]2,true,false
  • Known difference: sorteddictionary.keys.live
    { var d = new SortedDictionary<int, string> { [1] = "a" }; var keys = d.Keys; d[2] = "b"; return $"{keys.Count}"; }
    .NET2
    JS1
  • Same result as .NET: sortedset.ops
    { var s = new SortedSet<string> { "pear", "apple", "fig" }; s.Remove("fig"); return J(s) + $"{s.Min},{s.Max},{B(s.Add("apple"))},{s.Count}"; }
    [apple,pear]apple,pear,false,2
  • Same result as .NET: dict.missing.key
    new Dictionary<string, int>()["x"].ToString()
    EXN KeyNotFound
  • Same result as .NET: dict.add.duplicate
    { var d = new Dictionary<string, int>(); d.Add("a", 1); d.Add("a", 2); return "no exn"; }
    EXN Argument
  • Same result as .NET: dict.trygetvalue
    { var d = new Dictionary<string, int> { ["a"] = 1 }; var ok = d.TryGetValue("b", out var v); return $"{B(ok)},{v},{B(d.ContainsKey("a"))}"; }
    false,0,true
  • Same result as .NET: dict.kvp.tostring
    new Dictionary<string, int> { ["a"] = 1 }.First().ToString()
    [a, 1]
  • Same result as .NET: dict.tryadd.getordefault
    { var d = new Dictionary<string, int>(); d.TryAdd("a", 1); var b = d.TryAdd("a", 2); return $"{B(b)},{d["a"]},{d.GetValueOrDefault("z", 9)}"; }
    false,1,9
  • Same result as .NET: dict.comparer.ignorecase
    { var d = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase) { ["Key"] = 1 }; return B(d.ContainsKey("KEY")); }
    true
  • Same result as .NET: dict.tuple.key
    { var d = new Dictionary<(int, string), int> { [(1, "a")] = 5 }; return $"{d[(1, "a")]}"; }
    5
  • Same result as .NET: hashset.ops
    { var s = new HashSet<int> { 1, 2, 3 }; s.IntersectWith(new[] { 2, 3, 4 }); s.UnionWith(new[] { 9 }); return J(s.OrderBy(x => x)) + B(s.Add(2)); }
    [2,3,9]false
  • Same result as .NET: hashset.string.order
    J(new HashSet<string> { "z", "a", "m" })
    [z,a,m]
  • Same result as .NET: stack.queue
    { var s = new Stack<int>(); s.Push(1); s.Push(2); var q = new Queue<int>(); q.Enqueue(1); q.Enqueue(2); return $"{s.Pop()},{s.Peek()},{q.Dequeue()},{q.Count},{J(new Stack<int>(new[] { 1, 2, 3 }))}"; }
    2,1,1,1,[3,2,1]
  • Same result as .NET: stack.pop.empty
    $"{new Stack<int>().Pop()}"
    EXN InvalidOperation
  • Same result as .NET: sorteddictionary
    { var d = new SortedDictionary<string, int> { ["b"] = 1, ["a"] = 2 }; return J(d.Keys); }
    [a,b]
  • Same result as .NET: sortedset
    J(new SortedSet<int> { 5, 1, 3, 1 })
    [1,3,5]
  • Same result as .NET: linkedlist
    { var l = new LinkedList<int>(); l.AddLast(2); l.AddFirst(1); l.AddLast(3); return J(l) + l.First.Value; }
    [1,2,3]1
  • Same result as .NET: collection.expression
    { int[] a = [1, 2, 3]; List<int> l = [.. a, 4]; return J(l); }
    [1,2,3,4]
  • Known difference: span.sum
    { Span<int> s = stackalloc int[] { 1, 2, 3 }; var t = 0; foreach (var x in s) t += x; return $"{t}"; }
    .NET6
    JScompile error: not supported
  • Known difference: readonly.wrapper
    { var l = new List<int> { 1 }; var r = l.AsReadOnly(); l.Add(2); return $"{r.Count}"; }
    .NET2
    JS1
  • Known difference: list.capacity.tostring
    new List<int>().ToString()
    .NETSystem.Collections.Generic.List`1[System.Int32]
    JS""
  • Same result as .NET: tuple.tostring
    (1, "a", true).ToString() + "|" + Tuple.Create(1, 2).ToString()
    (1, a, True)|(1, 2)
  • Same result as .NET: tuple.equality
    B((1, "a") == (1, "a")) + "," + B((1, "a").Equals((1, "b")))
    true,false
  • Same result as .NET: tuple.named
    { var t = (Name: "x", Age: 3); var (n, a) = t; return $"{t.Name},{t.Item2},{n},{a}"; }
    x,3,x,3
  • Same result as .NET: tuple.swap
    { int a = 1, b = 2; (a, b) = (b, a); return $"{a},{b}"; }
    2,1
LINQ48 / 48 same as .NET
  • Same result as .NET: linq.where.select
    J(Enumerable.Range(1, 10).Where(x => x % 3 == 0).Select(x => x * x))
    [9,36,81]
  • Same result as .NET: linq.select.index
    J(new[] { "a", "b" }.Select((s, i) => $"{i},{s}"))
    [0,a,1,b]
  • Same result as .NET: linq.orderby.stable
    J(new[] { "bb", "a", "cc", "d", "ee" }.OrderBy(s => s.Length))
    [a,d,bb,cc,ee]
  • Same result as .NET: linq.orderby.thenby
    J(new[] { (2, "b"), (1, "z"), (2, "a"), (1, "a") }.OrderBy(t => t.Item1).ThenByDescending(t => t.Item2).Select(t => $"{t.Item1},{t.Item2}"))
    [1,z,1,a,2,b,2,a]
  • Same result as .NET: linq.orderby.strings.culture
    J(new[] { "b", "B", "a", "A", "_" }.OrderBy(s => s))
    [A,B,_,a,b]
  • Same result as .NET: linq.order
    J(new[] { 3, 1, 2 }.Order())
    [1,2,3]
  • Same result as .NET: linq.groupby
    J(new[] { 1, 2, 3, 4, 5 }.GroupBy(x => x % 2).Select(g => $"{g.Key}:{J(g)}"))
    [1:[1,3,5],0:[2,4]]
  • Same result as .NET: linq.groupby.resultselector
    J(new[] { "ab", "c", "de" }.GroupBy(s => s.Length, (k, g) => $"{k}={g.Count()}"))
    [2=2,1=1]
  • Same result as .NET: linq.tolookup
    { var l = new[] { "ab", "c", "de" }.ToLookup(s => s.Length); return $"{l[2].Count()},{l[9].Count()},{l.Count}"; }
    2,0,2
  • Same result as .NET: linq.tolookup.order
    { var l = new[] { "bb", "a", "cc", "d" }.ToLookup(s => s.Length, s => s.ToUpper()); return string.Join("|", l.Select(g => $"{g.Key}:{J(g)}")) + "," + B(l.Contains(2)); }
    2:[BB,CC]|1:[A,D],true
  • Same result as .NET: linq.take.range.fromend
    J(Enumerable.Range(1, 5).Take(^2..)) + J(new[] { 1, 2 }.Take(1..9)) + J(new[] { 1, 2 }.Take(3..1))
    [4,5][2][]
  • Same result as .NET: linq.todictionary.dup
    $"{new[] { 1, 1 }.ToDictionary(x => x).Count}"
    EXN Argument
  • Same result as .NET: linq.first.empty
    $"{new int[0].First()}"
    EXN InvalidOperation
  • Same result as .NET: linq.firstordefault
    $"{new int[0].FirstOrDefault()},{new string[0].FirstOrDefault() ?? "null"},{new[] { 1, 2 }.FirstOrDefault(x => x > 5, -1)}"
    0,null,-1
  • Same result as .NET: linq.single.many
    $"{new[] { 1, 2 }.Single()}"
    EXN InvalidOperation
  • Same result as .NET: linq.last.elementat
    $"{new[] { 1, 2, 3 }.Last()},{new[] { 1, 2, 3 }.ElementAt(1)},{new[] { 1 }.ElementAtOrDefault(5)}"
    3,2,0
  • Same result as .NET: linq.aggregate
    $"{Enumerable.Range(1, 5).Aggregate((a, b) => a * b)},{new[] { "a", "b" }.Aggregate("x", (acc, s) => acc + s, r => r.ToUpper())}"
    120,XAB
  • Same result as .NET: linq.sum.average
    $"{new[] { 1, 2, 3, 4 }.Average()},{new[] { 1.5, 2.5 }.Sum()},{new[] { 2, 4 }.Average(x => x * 1.0)}"
    2.5,4,3
  • Same result as .NET: linq.average.empty
    $"{new int[0].Average()}"
    EXN InvalidOperation
  • Same result as .NET: linq.sum.overflow
    $"{new[] { int.MaxValue, 1 }.Sum()}"
    EXN Overflow
  • Same result as .NET: linq.min.max
    $"{new[] { 3, 1, 2 }.Min()},{new[] { 3, 1, 2 }.Max()},{new[] { "bb", "a" }.MaxBy(s => s.Length)},{new[] { "bb", "a" }.MinBy(s => s.Length)}"
    1,3,bb,a
  • Same result as .NET: linq.min.empty
    $"{new int[0].Min()}"
    EXN InvalidOperation
  • Same result as .NET: linq.distinctby.unionby
    J(new[] { "a", "A", "b" }.DistinctBy(s => s.ToLower())) + J(new[] { 1, 2 }.Union(new[] { 2, 3 }))
    [a,b][1,2,3]
  • Same result as .NET: linq.except.intersect
    J(new[] { 1, 2, 3, 2 }.Except(new[] { 2 })) + J(new[] { 1, 2, 3 }.Intersect(new[] { 3, 2 }))
    [1,3][2,3]
  • Same result as .NET: linq.zip
    J(new[] { 1, 2, 3 }.Zip(new[] { "a", "b" }, (n, s) => $"{n},{s}")) + J(new[] { 1, 2 }.Zip(new[] { 'x', 'y' }).Select(t => $"{t.First},{t.Second}"))
    [1,a,2,b][1,x,2,y]
  • Same result as .NET: linq.skip.take
    J(Enumerable.Range(1, 10).Skip(2).Take(3)) + J(Enumerable.Range(1, 5).SkipWhile(x => x < 3).TakeWhile(x => x < 5)) + J(Enumerable.Range(1, 5).TakeLast(2)) + J(Enumerable.Range(1, 5).SkipLast(3))
    [3,4,5][3,4][4,5][1,2]
  • Same result as .NET: linq.take.range
    J(Enumerable.Range(1, 10).Take(2..4))
    [3,4]
  • Same result as .NET: linq.chunk
    J(Enumerable.Range(1, 5).Chunk(2).Select(c => J(c)))
    [[1,2],[3,4],[5]]
  • Same result as .NET: linq.selectmany
    J(new[] { "ab", "cd" }.SelectMany(s => s.ToCharArray()))
    [a,b,c,d]
  • Same result as .NET: linq.join
    J(new[] { (1, "a"), (2, "b") }.Join(new[] { (2, "x"), (1, "y"), (1, "z") }, l => l.Item1, r => r.Item1, (l, r) => l.Item2 + r.Item2))
    [ay,az,bx]
  • Same result as .NET: linq.groupjoin
    J(new[] { 1, 2 }.GroupJoin(new[] { 1, 1, 3 }, a => a, b => b, (a, bs) => $"{a}:{bs.Count()}"))
    [1:2,2:0]
  • Same result as .NET: linq.any.all.contains
    $"{B(new int[0].All(x => x > 0))},{B(new[] { 1 }.Any())},{B(new[] { 1, 2 }.Contains(2))}"
    true,true,true
  • Same result as .NET: linq.count.predicate
    $"{Enumerable.Range(1, 10).Count(x => x > 7)},{new[] { 1 }.LongCount()}"
    3,1
  • Same result as .NET: linq.repeat.empty.concat
    J(Enumerable.Repeat("x", 3).Concat(Enumerable.Empty<string>()).Append("y").Prepend("w"))
    [w,x,x,x,y]
  • Same result as .NET: linq.reverse.defaultifempty
    J(new[] { 1, 2 }.Reverse()) + J(new int[0].DefaultIfEmpty(7))
    [2,1][7]
  • Same result as .NET: linq.sequenceequal
    B(new[] { 1, 2 }.SequenceEqual(new List<int> { 1, 2 }))
    true
  • Same result as .NET: linq.cast.oftype
    J(new object[] { 1, "a", 2, null }.OfType<int>()) + J(new object[] { "a", "b" }.Cast<string>())
    [1,2][a,b]
  • Same result as .NET: linq.cast.invalid
    J(new object[] { 1, "a" }.Cast<int>())
    EXN InvalidCast
  • Same result as .NET: linq.cast.valid
    J(new object[] { "a", null, "b" }.Cast<string>().Select(s => s ?? "null")) + J(new object[] { 1, 2 }.Cast<int>())
    [a,null,b][1,2]
  • Same result as .NET: linq.sum.selector.overflow
    $"{new[] { 1, 2 }.Sum(x => int.MaxValue / 2 + x)}"
    EXN Overflow
  • Same result as .NET: linq.sum.long
    $"{new[] { long.MaxValue - 1, 1L }.Sum()}"
    9223372036854775807
  • Same result as .NET: linq.deferred
    { var log = new List<string>(); var q = Counted(log).Where(x => { log.Add($"w{x}"); return x % 2 == 0; }).Take(1); log.Add("built"); var r = q.ToList(); return J(log) + J(r); }
    [built,y1,w1,y2,w2][2]
  • Same result as .NET: linq.query.syntax
    J(from x in Enumerable.Range(1, 6) let sq = x * x where sq > 5 orderby x descending select $"{x}:{sq}")
    [6:36,5:25,4:16,3:9]
  • Same result as .NET: linq.query.group
    J(from w in new[] { "apple", "avocado", "banana" } group w by w[0] into g select $"{g.Key},{g.Count()}")
    [a,2,b,1]
  • Same result as .NET: linq.toarray.tolist.tohashset
    $"{new[] { 1, 1, 2 }.ToHashSet().Count},{new[] { 1 }.ToList().Count}"
    2,1
  • Same result as .NET: linq.range.negative
    J(Enumerable.Range(1, -1))
    EXN ArgumentOutOfRange
  • Same result as .NET: linq.index
    J(new[] { "a", "b" }.Index().Select(t => $"{t.Index},{t.Item}"))
    [0,a,1,b]
  • Same result as .NET: linq.countby.aggregateby
    J(new[] { "a", "b", "a" }.CountBy(s => s).Select(kv => $"{kv.Key},{kv.Value}"))
    [a,2,b,1]
Language41 / 42 same as .NET
  • Same result as .NET: closure.loop.capture.for
    { var fs = new List<Func<int>>(); for (int i = 0; i < 3; i++) fs.Add(() => i); return J(fs.Select(f => f())); }
    [3,3,3]
  • Same result as .NET: closure.loop.capture.foreach
    { var fs = new List<Func<int>>(); foreach (var i in new[] { 0, 1, 2 }) fs.Add(() => i); return J(fs.Select(f => f())); }
    [0,1,2]
  • Same result as .NET: closure.mutation
    { int x = 1; Action inc = () => x++; inc(); inc(); return $"{x}"; }
    3
  • Same result as .NET: local.function.recursive
    { int Fact(int n) => n <= 1 ? 1 : n * Fact(n - 1); return $"{Fact(10)}"; }
    3628800
  • Same result as .NET: static.local.function
    { static int Sq(int n) => n * n; return $"{Sq(7)}"; }
    49
  • Same result as .NET: optional.named.args
    Opt(1) + "|" + Opt(1, c: "z") + "|" + Names(last: "L")
    1,2,c|1,2,z|fL
  • Same result as .NET: params
    $"{Sum()},{Sum(1, 2, 3)},{Sum(new[] { 4, 5 })}"
    0,6,9
  • Same result as .NET: out.ref
    { int b = 3; Out(out var a, ref b); return $"{a},{b}"; }
    5,6
  • Same result as .NET: ref.local
    { var arr = new[] { 1, 2 }; ref int r = ref arr[1]; r = 9; return J(arr); }
    [1,9]
  • Same result as .NET: iterator.lazy.infinite
    J(Fib().Skip(10).Take(3))
    [55,89,144]
  • Same result as .NET: iterator.finally.on.dispose
    { var log = new List<string>(); foreach (var s in WithFinally(log)) { log.Add(s); break; } return J(log); }
    [a,finally]
  • Same result as .NET: iterator.yield.break
    J(YieldBreak(3))
    [0,1,2]
  • Same result as .NET: iterator.reenumerate
    { var e = YieldBreak(2); return J(e) + J(e); }
    [0,1][0,1]
  • Same result as .NET: exception.custom
    { try { throw new CustomException("boom", 42); } catch (CustomException e) { return $"{e.Message},{e.Code}"; } }
    boom,42
  • Same result as .NET: exception.message
    { try { throw new InvalidOperationException("bad op"); } catch (Exception e) { return e.Message; } }
    bad op
  • Same result as .NET: exception.filter
    { try { throw new CustomException("x", 2); } catch (CustomException e) when (e.Code == 1) { return "one"; } catch (CustomException e) when (e.Code == 2) { return "two"; } }
    two
  • Same result as .NET: exception.finally.order
    { var log = new List<string>(); try { try { log.Add("try"); throw new Exception("e"); } finally { log.Add("finally"); } } catch { log.Add("catch"); } return J(log); }
    [try,finally,catch]
  • Same result as .NET: exception.rethrow
    { try { try { throw new ArgumentException("inner"); } catch (Exception) { throw; } } catch (ArgumentException e) { return e.Message; } }
    inner
  • Same result as .NET: exception.inner
    { var e = new Exception("outer", new Exception("inner")); return e.InnerException.Message; }
    inner
  • Known difference: exception.null.deref
    { string s = null; return $"{s.Length}"; }
    .NETEXN NullReference
    JSEXN Exception
  • Same result as .NET: exception.tostring.prefix
    new InvalidOperationException("m").Message
    m
  • Same result as .NET: using.dispose.order
    { var log = new List<string>(); using (var a = new Disp(log, "a")) using (var b = new Disp(log, "b")) { log.Add("body"); } return J(log); }
    [body,dispose b,dispose a]
  • Same result as .NET: using.declaration
    { var log = new List<string>(); void Run() { using var a = new Disp(log, "a"); log.Add("body"); } Run(); return J(log); }
    [body,dispose a]
  • Same result as .NET: events
    { var c = new Counter(); var log = new List<int>(); Action<int> h = v => log.Add(v); c.Changed += h; c.Inc(); c.Changed -= h; c.Inc(); return J(log) + c.Value; }
    [1]2
  • Same result as .NET: operator.overload.implicit
    { var c = new Counter(); c += 3; int v = c; return $"{v},{c[2]}"; }
    3,6
  • Same result as .NET: static.field
    { Counter.Instances = 0; new Counter(); new Counter(); return $"{Counter.Instances}"; }
    2
  • Same result as .NET: delegate.multicast
    { var log = new List<string>(); Action a = () => log.Add("1"); a += () => log.Add("2"); a(); return J(log); }
    [1,2]
  • Same result as .NET: delegate.multicast.return
    { Func<int> f = () => 1; f += () => 2; return $"{f()}"; }
    2
  • Same result as .NET: func.compose
    { Func<int, int> inc = x => x + 1; Func<int, int> dbl = x => x * 2; Func<int, int> both = x => dbl(inc(x)); return $"{both(3)}"; }
    8
  • Same result as .NET: struct.copy.semantics
    { var a = new MutPoint(); var b = a; b.Move(); var arr = new[] { a }; arr[0].Move(); var list = new List<MutPoint> { a }; var l0 = list[0]; l0.Move(); return $"{a.X},{b.X},{arr[0].X},{list[0].X}"; }
    0,1,1,0
  • Same result as .NET: struct.default.equality
    B(new MutPoint().Equals(new MutPoint())) + "," + B(new MutPoint { X = 1 }.Equals(new MutPoint()))
    true,false
  • Same result as .NET: null.conditional
    { Counter c = null; int? v = c?.Value; string s = null; return $"{v?.ToString() ?? "none"},{s?.Length ?? -1}"; }
    none,-1
  • Same result as .NET: null.coalescing.assign
    { List<int> l = null; l ??= new List<int>(); l.Add(1); string s = null; s ??= "d"; return $"{l.Count},{s}"; }
    1,d
  • Same result as .NET: conditional.chain
    { int x = 5; return x > 3 ? x > 4 ? "big" : "mid" : "small"; }
    big
  • Same result as .NET: goto.labels
    { int i = 0; again: i++; if (i < 3) goto again; return $"{i}"; }
    3
  • Same result as .NET: while.dowhile.continue
    { var r = ""; int i = 0; do { i++; if (i == 2) continue; r += i; } while (i < 4); while (i > 0) { i--; if (i == 1) break; } return r + i; }
    1341
  • Same result as .NET: lazy
    { var n = 0; var l = new Lazy<int>(() => ++n); var a = l.Value; var b = l.Value; return $"{a},{b},{n},{B(l.IsValueCreated)}"; }
    1,1,1,true
  • Same result as .NET: default.literal
    { int i = default; string s = default; return $"{i},{s ?? "null"}"; }
    0,null
  • Same result as .NET: nameof
    nameof(Counter.Value) + nameof(Language)
    ValueLanguage
  • Same result as .NET: checked.unchecked.block
    { int m = int.MaxValue; int r = unchecked(m + 1); return $"{r}"; }
    -2147483648
  • Same result as .NET: discard.assign
    { _ = int.TryParse("5", out var v); return $"{v}"; }
    5
  • Same result as .NET: lambda.static.default.params
    { var f = (int a, int b = 10) => a + b; return $"{f(1)},{f(1, 2)}"; }
    11,3
Pattern matching24 / 25 same as .NET
  • Same result as .NET: switch.type.patterns
    string.Join("|", new object[] { null, -1, 3, "", "x", new Point(0, 0), new Point(2, 2), new Point(1, 3), new[] { 7, 8, 9 }, 1.5 }.Select2(Classify))
    null|negative int|int 3|empty string|string x|origin|diagonal 2|point 1|long array 7|other
  • Same result as .NET: switch.property.positional
    $"{Area(new Circle(1))},{Area(new Rect(2, 3))}"
    3.14,6
  • Same result as .NET: switch.throw.arm
    $"{Area(null)}"
    EXN Argument
  • Same result as .NET: switch.relational
    string.Join(",", new[] { 95, 85, 50, -1, 101 }.Select2(Grade))
    A,B,C,invalid,A
  • Same result as .NET: switch.list.patterns
    string.Join("|", new[] { new int[0], new[] { 1 }, new[] { 1, 2 }, new[] { 1, 2, 3, 4 } }.Select2(ListPat))
    empty|one 1|two 1,2|many 1..4
  • Same result as .NET: switch.list.slice
    SliceLen(new[] { 1, 2, 3, 4, 5 }) + "," + SliceLen(new[] { 1 })
    3,short
  • Same result as .NET: switch.tuple
    $"{Tuple(0, true)},{Tuple(5, true)},{Tuple(20, false)},{Tuple(3, false)}"
    zero,flag,big,rest
  • Same result as .NET: switch.nomatch
    { int x = 7; var r = x switch { 1 => "one", 2 => "two" }; return r; }
    EXN InvalidOperation
  • Same result as .NET: is.not.null
    { object o = "s"; return B(o is not null) + "," + B(o is string { Length: 1 }); }
    true,true
  • Same result as .NET: is.type.var
    { object o = 42; if (o is int n && n > 40) return $"{n + 1}"; return "no"; }
    43
  • Same result as .NET: as.cast
    { object o = "x"; var s = o as string; var p = o as Point; return $"{s}|{(p == null ? "null" : "p")}"; }
    x|null
  • Same result as .NET: cast.invalid
    { object o = "x"; var p = (Point)o; return p.ToString(); }
    EXN InvalidCast
  • Same result as .NET: cast.valid
    { object o = new Dog(); Animal a = (Animal)o; object n = null; var d = (Dog)n; return a.Sound() + "," + B(d == null); }
    woof,true
  • Same result as .NET: unbox.invalid
    { object o = "a"; return $"{(int)o}"; }
    EXN InvalidCast
  • Same result as .NET: unbox.valid
    { object o = 5, b = true; return $"{(int)o},{(bool)b}"; }
    5,True
  • Same result as .NET: reference.equality.class
    { var a = new Dog(); Animal b = a; object c = new Dog(); return B(a == b) + "," + B(a != c) + "," + B((object)null == null); }
    true,true,true
  • Same result as .NET: switch.statement.goto
    { var r = ""; for (int i = 0; i < 4; i++) { switch (i) { case 0: case 1: r += "a"; break; case 2: r += "b"; break; default: r += "c"; break; } } return r; }
    aabc
  • Same result as .NET: switch.string
    { string s = "two"; switch (s) { case "one": return "1"; case "two": return "2"; default: return "?"; } }
    2
  • Same result as .NET: enum.tostring
    $"{Color.Green}|{(Color)6}|{(int)Color.Blue}|{(Color)42}"
    Green|Blue|6|42
  • Same result as .NET: enum.flags.tostring
    $"{Perm.Read | Perm.Write}|{Perm.None}"
    Read, Write|None
  • Same result as .NET: enum.hasflag
    B((Perm.Read | Perm.Exec).HasFlag(Perm.Exec)) + "," + B((Perm.Read).HasFlag(Perm.Write))
    true,false
  • Same result as .NET: enum.parse
    $"{Enum.Parse<Color>("Blue")}|{(int)Enum.Parse<Color>("Green")}"
    Blue|5
  • Same result as .NET: enum.tryparse
    { var ok = Enum.TryParse<Color>("Purple", out var c); return $"{B(ok)},{c}"; }
    false,Red
  • Known difference: enum.getvalues
    J(Enum.GetValues<Color>())
    .NET[Red,Green,Blue]
    JS[0,5,6]
  • Same result as .NET: enum.switch
    Color.Blue switch { Color.Red => "r", Color.Blue => "b", _ => "?" }
    b
Records and structs29 / 29 same as .NET
  • Same result as .NET: record.tostring
    new Point(1, 2).ToString()
    Point { X = 1, Y = 2 }
  • Same result as .NET: record.tostring.nested
    new Nested(new Point(1, 2), "a").ToString()
    Nested { P = Point { X = 1, Y = 2 }, Label = a }
  • Same result as .NET: record.tostring.derived
    new Point3(1, 2, 3).ToString()
    Point3 { X = 1, Y = 2, Z = 3 }
  • Same result as .NET: record.tostring.body
    new WithBody { A = "x", B = 2 }.ToString()
    WithBody { A = x, B = 2 }
  • Same result as .NET: record.equality
    B(new Point(1, 2) == new Point(1, 2)) + "," + B(new Point(1, 2).Equals(new Point(1, 2))) + "," + B(new Point(1, 2) != new Point(2, 1))
    true,true,true
  • Same result as .NET: record.equality.object
    B(((object)new Point(1, 2)).Equals(new Point(1, 2)))
    true
  • Same result as .NET: record.equality.derived
    B(new Point(1, 2) == new Point3(1, 2, 0))
    false
  • Same result as .NET: record.equality.nested
    B(new Nested(new Point(1, 2), "a") == new Nested(new Point(1, 2), "a"))
    true
  • Same result as .NET: record.equality.array.member
    { var t = new[] { 1 }; return B(new Tagged("a", t) == new Tagged("a", t)) + "," + B(new Tagged("a", new[] { 1 }) == new Tagged("a", new[] { 1 })); }
    true,false
  • Same result as .NET: record.hash.equal
    B(new Point(1, 2).GetHashCode() == new Point(1, 2).GetHashCode())
    true
  • Same result as .NET: record.with
    (new Person("Ann", 30) with { Age = 31 }).ToString()
    Person { Name = Ann, Age = 31, Greeting = Hi Ann }
  • Same result as .NET: record.with.derived
    { Point p = new Point3(1, 2, 3); var q = p with { X = 9 }; return q.ToString(); }
    Point3 { X = 9, Y = 2, Z = 3 }
  • Same result as .NET: record.with.unchanged.original
    { var a = new Person("Ann", 30); var b = a with { Name = "Bo" }; return a.Name + b.Name; }
    AnnBo
  • Same result as .NET: record.deconstruct
    { var (x, y) = new Point(3, 4); return $"{x},{y}"; }
    3,4
  • Same result as .NET: record.computed.member
    new Person("Ann", 30).Greeting
    Hi Ann
  • Same result as .NET: record.in.hashset
    { var s = new HashSet<Point> { new Point(1, 2), new Point(1, 2), new Point(2, 1) }; return $"{s.Count}"; }
    2
  • Same result as .NET: record.as.dict.key
    { var d = new Dictionary<Point, string> { [new Point(1, 2)] = "a" }; return d[new Point(1, 2)]; }
    a
  • Same result as .NET: record.distinct
    $"{new[] { new Point(1, 2), new Point(1, 2) }.Distinct().Count()}"
    1
  • Same result as .NET: record.groupby
    $"{new[] { new Point(1, 2), new Point(1, 2), new Point(0, 0) }.GroupBy(p => p).Count()}"
    2
  • Same result as .NET: record.struct.tostring
    new Vec(1.5, 2).ToString()
    Vec { X = 1.5, Y = 2 }
  • Same result as .NET: record.struct.equality
    B(new Vec(1, 2) == new Vec(1, 2)) + "," + B(new Money("EUR", 5).Equals(new Money("EUR", 5)))
    true,true
  • Same result as .NET: record.struct.copy
    { var a = new Vec(1, 2); var b = a; b.X = 9; return $"{a.X},{b.X}"; }
    1,9
  • Same result as .NET: record.struct.with
    (new Money("EUR", 5) with { Cents = 7 }).ToString()
    Money { Currency = EUR, Cents = 7 }
  • Same result as .NET: record.struct.default
    default(Vec).ToString()
    Vec { X = 0, Y = 0 }
  • Same result as .NET: record.equals.null
    { Point p = null; return B(p == null) + "," + B(new Point(1, 2).Equals(null)); }
    true,false
  • Same result as .NET: record.reference.equals
    B(ReferenceEquals(new Point(1, 2), new Point(1, 2)))
    false
  • Same result as .NET: record.init.props
    { var w = new WithBody { A = "a" }; return $"{w.A},{w.B}"; }
    a,0
  • Same result as .NET: record.list.contains
    B(new List<Point> { new Point(1, 2) }.Contains(new Point(1, 2)))
    true
  • Same result as .NET: record.indexof
    $"{Array.IndexOf(new[] { new Point(0, 0), new Point(1, 2) }, new Point(1, 2))}"
    1
Types and dates37 / 44 same as .NET
  • Same result as .NET: interface.default.method
    { IGreeter a = new Plain(), b = new Custom(); return a.Greet() + "|" + b.Greet(); }
    Hello plain|Yo
  • Same result as .NET: virtual.dispatch
    new Dog().Describe() + "|" + new Puppy().Describe()
    dog says woof|puppy says woof!
  • Same result as .NET: new.hiding
    { var h = new Hider(); Dog d = h; return h.Sound() + "|" + d.Sound(); }
    hidden|woof
  • Same result as .NET: generic.constraint
    B(new Box<int>(5).Bigger(3)) + "," + B(new Box<string>("a").Bigger("b"))
    true,false
  • Known difference: generic.default
    $"{Box<int>.Default()}|{Box<string>.Default() ?? "null"}"
    .NET0|null
    JSnull|null
  • Same result as .NET: generic.method.max
    $"{Max(3, 9)},{Max("b", "a")}"
    9,b
  • Same result as .NET: generic.tostring
    $"{Generic(1)},{Generic<string>(null)},{Generic(1.5)}"
    1,null,1.5
  • Same result as .NET: ctor.chaining.order
    { Ctor.Log.Clear(); new Ctor(); return J(Ctor.Log); }
    [field,ctor(1),ctor()]
  • Same result as .NET: required.init
    { var r = new Required { Name = "n" }; return $"{r.Name},{r.Age}"; }
    n,18
  • Same result as .NET: primary.ctor
    { var p = new PrimaryCtor("x", 1); p.Birthday(); return p.Describe(); }
    x/2
  • Same result as .NET: override.equals
    B(new Eq { Id = 1 }.Equals(new Eq { Id = 1 })) + "," + B(new Eq { Id = 1 } == new Eq { Id = 1 }) + "," + $"{new[] { new Eq { Id = 1 }, new Eq { Id = 1 } }.Distinct().Count()}"
    true,false,1
  • Same result as .NET: override.equals.dictionary
    { var d = new Dictionary<Eq, int> { [new Eq { Id = 3 }] = 7 }; return $"{d[new Eq { Id = 3 }]}"; }
    7
  • Same result as .NET: override.tostring
    $"{new WithToString()}|{string.Concat(new WithToString(), "")}"
    custom!|custom!
  • Known difference: object.tostring.default
    new Plain().ToString()
    .NETConformance.Plain
    JS[object Object]
  • Known difference: gettype.name
    new Dog().GetType().Name
    .NETDog
    JScompile error: not supported
  • Known difference: typeof.name
    typeof(Dog).Name + "|" + typeof(List<int>).Name
    .NETDog|List`1
    JScompile error: not supported
  • Known difference: typeof.fullname
    typeof(Dog).FullName + "|" + typeof(Dog).Namespace + "|" + typeof(string).FullName + "|" + typeof(Dictionary<string, int>).Name
    .NETConformance.Dog|Conformance|System.String|Dictionary`2
    JScompile error: not supported
  • Same result as .NET: is.base.interface
    { object d = new Puppy(); return B(d is Animal) + B(d is IGreeter) + B(d is Dog); }
    truefalsetrue
  • Known difference: boxing.equality
    { object a = 1, b = 1; return B(a == b) + "," + B(a.Equals(b)) + "," + B(Equals(a, b)); }
    .NETfalse,true,true
    JStrue,true,true
  • Same result as .NET: boxing.int.long
    { object a = 1, b = 1L; return B(a.Equals(b)); }
    false
  • Same result as .NET: anonymous.type
    { var a = new { X = 1, Y = "y" }; var b = new { X = 1, Y = "y" }; return a.ToString() + "|" + B(a.Equals(b)); }
    { X = 1, Y = y }|true
  • Same result as .NET: datetime.basic
    { var d = new DateTime(2024, 2, 29, 13, 5, 9); return $"{d.Year}-{d.Month}-{d.Day} {d.Hour}:{d.Minute}:{d.Second} {d.DayOfWeek} {d.DayOfYear}"; }
    2024-2-29 13:5:9 Thursday 60
  • Same result as .NET: datetime.arith
    { var d = new DateTime(2024, 1, 31); return $"{d.AddMonths(1):yyyy-MM-dd}|{d.AddDays(1):yyyy-MM-dd}|{(new DateTime(2024, 3, 1) - d).TotalDays}"; }
    2024-02-29|2024-02-01|30
  • Same result as .NET: datetime.format
    new DateTime(2024, 7, 4, 9, 3, 0).ToString("yyyy-MM-dd HH:mm:ss") + "|" + new DateTime(2024, 7, 4).ToString("ddd, dd MMM yyyy")
    2024-07-04 09:03:00|Thu, 04 Jul 2024
  • Known difference: datetime.iso
    new DateTime(2024, 7, 4, 9, 3, 0, DateTimeKind.Utc).ToString("o")
    .NET2024-07-04T09:03:00.0000000Z
    JS2024-07-04T11:03:00.0000000+02:00
  • Same result as .NET: datetime.parse
    DateTime.Parse("2024-07-04T09:03:00").ToString("yyyy/MM/dd HH:mm")
    2024/07/04 09:03
  • Same result as .NET: timespan
    { var t = TimeSpan.FromMinutes(90) + TimeSpan.FromSeconds(30); return $"{t}|{t.TotalHours}|{t.Hours}|{t.Minutes}"; }
    01:30:30|1.5083333333333333|1|30
  • Same result as .NET: timespan.format
    TimeSpan.FromMilliseconds(3723004).ToString(@"hh\:mm\:ss\.fff")
    01:02:03.004
  • Same result as .NET: timespan.format.standard
    { var t = new TimeSpan(1, 2, 3, 4, 50); return t.ToString("c") + "|" + t.ToString("g") + "|" + t.ToString("G") + "|" + TimeSpan.FromMinutes(5).ToString("g"); }
    1.02:03:04.0500000|1:2:03:04.05|1:02:03:04.0500000|0:05:00
  • Same result as .NET: timespan.format.custom
    { var t = new TimeSpan(3, 4, 5, 6, 70); return t.ToString(@"d\.hh\:mm") + "|" + t.ToString("%d") + "|" + t.ToString(@"dd' days' h' h'") + "|" + t.ToString(@"ss\.FFF"); }
    EXN Format
  • Same result as .NET: anonymous.type.nested
    { var a = new { Name = (string)null, Flag = true, Inner = new { V = 1.5 } }; return $"{a}|{new { }}"; }
    { Name = , Flag = True, Inner = { V = 1.5 } }|{ }
  • Same result as .NET: dateonly
    new DateOnly(2024, 2, 28).AddDays(2).ToString("yyyy-MM-dd")
    2024-03-01
  • Same result as .NET: dateonly.ops
    { var d = new DateOnly(2024, 1, 31); var e = d.AddMonths(1); return $"{e.Year}-{e.Month}-{e.Day},{e.DayOfWeek},{B(d < e)},{B(new DateOnly(2024, 3, 1) == d.AddDays(30))},{d.AddYears(1):yyyy/MM/dd}"; }
    2024-2-29,Thursday,true,true,2025/01/31
  • Same result as .NET: dateonly.tostring
    $"{new DateOnly(2024, 7, 4)}|" + new DateOnly(2024, 7, 4).ToString()
    07/04/2024|07/04/2024
  • Same result as .NET: guid.parse.format
    { var g = Guid.Parse("0f8fad5b-d9cb-469f-a165-70867728950e"); return g.ToString() + "|" + g.ToString("N") + "|" + B(g == new Guid("0F8FAD5B-D9CB-469F-A165-70867728950E")); }
    0f8fad5b-d9cb-469f-a165-70867728950e|0f8fad5bd9cb469fa16570867728950e|true
  • Same result as .NET: guid.empty
    Guid.Empty.ToString()
    00000000-0000-0000-0000-000000000000
  • Same result as .NET: random.seeded.range
    { var r = new Random(1); var x = r.Next(10); return B(x >= 0 && x < 10); }
    true
  • Same result as .NET: nullable.struct.getvalueordefault
    { int? a = null; return $"{a.GetValueOrDefault()},{a.GetValueOrDefault(4)}"; }
    0,4
  • Same result as .NET: nullable.value.null
    { int? a = null; return $"{a.Value}"; }
    EXN InvalidOperation
  • Same result as .NET: convert.tostring.bool
    true.ToString() + "|" + bool.Parse("TRUE")
    True|True
  • Same result as .NET: string.gethashcode.stable
    B("abc".GetHashCode() == "abc".GetHashCode())
    true
  • Same result as .NET: valuetuple.compare
    $"{Math.Sign((1, 2).CompareTo((1, 3)))}"
    -1
  • Same result as .NET: comparer.default
    $"{Math.Sign(Comparer<string>.Default.Compare("a", "B"))},{Math.Sign(Comparer<int>.Default.Compare(2, 1))}"
    1,1
  • Same result as .NET: equalitycomparer.default
    B(EqualityComparer<Point>.Default.Equals(new Point(1, 1), new Point(1, 1)))
    true

How this is computed

The cases live in WebSharper's own repository (tests/WebSharper.CSharp.Conformance). The same C# project is built for .NET and with WebSharper, run on .NET and under Node, and the outputs are compared. The check runs on every release build against a committed baseline, so a change that makes any case worse fails the build. The TypeScript declarations WebSharper generates for the cases are type-checked too.

Same as .NET: JavaScript prints exactly what .NET prints.
Known difference: an accepted difference that follows from JavaScript, listed above with its alternative.
Mismatch: a different result with no accepted reason, a bug to fix.

For tools and AI agents

The results are published as JSON: every case with its C# source, its .NET output and its status, and the known differences with their reasons and alternatives.

Whether an API translates at all is a separate question: see API coverage.