c# return proper value formatted by type (c# printing to Excel for example)

#297
Raw
Author
Anonymous
Created
Nov. 30, 2020, 9:56 p.m.
Expires
Never
Size
470 bytes
Hits
67
Syntax
C#
private Object FormattedValueByType(Object value)
{
    if (value is string @string)
    {
        if (Double.TryParse(@string, out double number))
        {
            return number;
        }
        else
        {
            return value;
        }
    }

    switch (value)
    {
        case double d: return (double)d;
        case int i: return i;
        default: return value;
    }
}