Skip to content

Latest commit

 

History

History
50 lines (35 loc) · 1.01 KB

JValueCast.md

File metadata and controls

50 lines (35 loc) · 1.01 KB

Casting JValue

This sample casts Argon.JValue instances to .NET values.

var v1 = new JValue("1");
var i = (int) v1;

Console.WriteLine(i);
// 1

var v2 = new JValue(true);
var b = (bool) v2;

Console.WriteLine(b);
// true

var v3 = new JValue("19.95");
var d = (decimal) v3;

Console.WriteLine(d);
// 19.95

var v4 = new JValue(new DateTime(2013, 1, 21));
var s = (string) v4;

Console.WriteLine(s);
// 01/21/2013 00:00:00

var v5 = new JValue("http://www.bing.com");
var u = (Uri) v5;

Console.WriteLine(u);
// http://www.bing.com/

var v6 = JValue.CreateNull();
u = (Uri) v6;

Console.WriteLine(u == null ? "{null}" : u.ToString());
// {null}

var dt = (DateTime?) v6;

Console.WriteLine(dt == null ? "{null}" : dt.ToString());
// {null}

snippet source | anchor