4

When I am checking my cache to see if if my ValueTuple is in the cache, I use the code below. In this scenario, the value coming back is null (aka does not exist in the cache). When the code runs I get object not set to instance of an object error on the 1st line. Is there a proper way to cast an object to a ValueTuple?

var geo = ((double, double))CacheEngine.Get(key);
if (!geo.Equals(default(ValueTuple<double, double>))) return geo;
Chris Auer
  • 1,405
  • 12
  • 23

1 Answers1

10

I found that I needed to do it like this to work. You need to cast to ValueTuple<double, double> and not (double, double).

var geo = CacheEngine.Get(key);
if (geo != null)
{
    var geoTuple = (ValueTuple<double, double>)geo;
    if (!geoTuple.Equals(default(ValueTuple<double, double>)))
    return geoTuple;
}
Chris Auer
  • 1,405
  • 12
  • 23