How to use unchecked to suppress overflow checking in C#

1 Answer

0 votes
using System;

class Program
{
    static void Main() {
        // error CS0220: The operation overflows at compile time in checked mode
        // int n1 = 2147483647 + 30; 
        int n2 = unchecked(2147483647 + 30);

        Console.Write(n2);
    }
}



/*
run:

-2147483619

*/

 



answered Nov 23, 2020 by avibootz

Related questions

1 answer 153 views
1 answer 140 views
1 answer 125 views
1 answer 127 views
1 answer 83 views
...