Skip to content

Instantly share code, notes, and snippets.

@mythz
Forked from gistlyn/main.cs
Last active July 9, 2017 07:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mythz/f9889fdf116076b6bc11c5d81d88bed0 to your computer and use it in GitHub Desktop.
Save mythz/f9889fdf116076b6bc11c5d81d88bed0 to your computer and use it in GitHub Desktop.
What is going on?
var n = "1";
object value;
var hasDecimal = n.IndexOf('.') >= 0;
value = hasDecimal
? double.Parse(n)
: int.Parse(n);
System.Console.WriteLine($"{value} is {value.GetType().Name}");
if (hasDecimal)
{
value = double.Parse(n);
}
else
{
value = int.Parse(n);
}
System.Console.WriteLine($"{value} is {value.GetType().Name}");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment