I want to use the System.Json.JsonArray.Contains() to see if my Array contains a specific value. Below is a minimum example. I expect both varibales bar and baz to be true
, but they're both false
.
nuget package System.Json v4.5 was used.
using System;
using System.Json;
public class Program
{
public static void Main()
{
bool bar = ((JsonArray)JsonValue.Parse("{\"foo\": [1,2,3]}")["foo"]).Contains(2);
bool baz = ((JsonArray)JsonValue.Parse("{\"foo\": [1,2,3]}")["foo"]).Contains(new JsonPrimitive(2));
Console.WriteLine($"contains 2?: {bar} {baz}");
Console.ReadKey();
}
}
Using System.Json, how do I check, if an array contains a numeric value and why does the above example return false?