.NET Fiddle

CSharp · Console

/Program.cs

using System;
					
public class Program
{
	public class Foo
	{
		public decimal Bar;
	}
	
	public static void Main()
	{
		var max = 10.00M;
		
		var foo = new Foo() { Bar = 5 };
		
		if (foo?.Bar > max)
			Console.WriteLine($"{foo?.Bar} is too large. Max is {max}.");
		else
			Console.WriteLine($"Value is: {foo?.Bar}");
		
		foo.Bar = 12;
		
		if (foo?.Bar > max)
			Console.WriteLine($"{foo?.Bar} is too large. Max is {max}.");
		else
			Console.WriteLine($"Value is: {foo?.Bar}");
		
		foo = null;
		
		if (foo?.Bar > max)
			Console.WriteLine($"{foo?.Bar} is too large. Max is {max}.");
		else
			Console.WriteLine($"Value is: {foo?.Bar}");
	}
}
;