For example, let’s use the Add method of the ArrayList class. If I am using the default compiler settings in Visual Studio C# project in which arithmetic overflow is not checked, would ArrayList.Add() throw an OverflowException if I added too many items? Would surrounding the method call with checked or unchecked make any difference?
BTW, I would write a test program to determine the answer to this question if I had Visual Studio available to me right now.
In general no the BCL does not run with overflow checking enabled. Enabling it in your application will have no affect on already compiled binaries only on your code.
Imagine all of the problems that would arise if you could control how the BCL code executed. Every time you authored an arithmetic expression you would have to consider how it would function in both scenarios in order to have 100% reliable code. Because anyone could change the semantics by using a
checked/uncheckedblock to call you.Think of all of the fun you could have with security sensitive API’s if you could turn off overflow checking in places they expect it to function.