Thursday, 30 March 2017

C# - Fix Error - Cannot implicitly convert type 'bool?' to 'bool'.


Watch this example on YouTube

Error    CS0266    Cannot implicitly convert type 'bool?' to 'bool'. An explicit conversion exists (are you missing a cast?)

To fix it replace

    string test = "FALSE";
            bool? test2 = null;
            if (test2)
            {
                test = "OK";
            }

with
    string test = "FALSE";
            bool? test2 = null;
            if (test2 != null)
            {
                test = "OK";
            }

No comments:

Post a Comment