I have created a test code snippet demonstrating what I am trying to achieve. But it does not work as expected (see comments in code):
public class Program
{
public static void Main()
{
object obj = null;
decimal? nullDecimal = null;
Test(obj); // Expected: Something else, Actual: Something else
Test(nullDecimal); // Expected: Nullable decimal, Actual: Something else
}
public static void Test(object value)
{
if (value is decimal)
{
Console.WriteLine("Decimal");
return;
}
if (value is decimal?)
{
Console.WriteLine("Nullable decimal");
return;
}
Console.WriteLine("Something else");
}
}
Is it even possible in .NET?