Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
EricomQ9
namespace Rextester { using System; public class Program { public static void Main(string[] args) { TestMethod(); } static void TestMethod() { // even if compiling with Roslyn the invalid checks below // DO NOT trigger a compiler warning DateTime dt = DateTime.MaxValue; if (dt == null) { } bool isEq = dt == null; // but trigger warning CS0472 for numeric types // The result of the expression is always 'false' since a value of type '<TYPENAME>' is never equal to 'null' of type '<TYPENAME>?' float i = 0; if (i == null) { } isEq = i == null; // warning CS0464: Comparing with null of type 'DateTime?' always produces 'false' bool isGreater = dt > null; if (i > null) { } // calling with a null argument gives a compile time error // CS1503: Argument 1: cannot convert from '<null>' to 'DateTime' //DateFunction(null); // this is valid but condition never evaluates DateFunction(DateTime.MinValue); // use a nullable type instead DateTimeFunction(null); DateTimeFunction(DateTime.MinValue); DateTimeFunction(DateTime.MaxValue); } static void DateFunction(DateTime time) { if (time == null) { /* do something */ } else { Console.WriteLine("Impossible null check for value types."); Console.WriteLine("Always evaluates to false."); Console.WriteLine("Should have triggered a compiler warning."); } } static void DateTimeFunction(DateTime? time) { if (time == null) { /* do something */ } else { Console.WriteLine(time.Value); } } } }
run
|
edit
|
history
|
help
0
SIN_in_Pow
6.4 Parallelism: threads and events
Display the pattern like diamond by using c# for loop
a5
Using System.Reflection to find Property Name and Value of any Generic class
salary
fgtyhi8uy7htr4e3qwcedf
code 1
|= Caching
simple hello world