On a recent post, someone asked about the Int32.DontTouchThis() method..  I thought more folks would want to hear it...

From int32.cs
#if _DEBUG
private void DontTouchThis() {
m_value = 0;
}
#endif

Our C# compiler has some great logic for detecting unused fields. Unfortunately the compiler didn’t special case the base class library. We got compiler warnings when compiling Int32 and some other classes saying their internal m_value field either wasn’t used, or always had its default value of 0. The compiler warning here is an error (the field was there for suitable, base level reasons). Instead of disabling those warnings globally for mscorlib (which would have hidden problems in other classes) we ended up adding in these DontTouchThis methods to convince the compiler that we’re doing something with that field, to simply silence the compiler warning.

Now we do have the relatively new #pragma support in the C# compiler, so we can disable these warnings on a finer grained level. However, we left many of the classes with the DontTouchThis method as-is, simply because of time. Since we don’t include the DontTouchThis methods in retail builds, we get almost no gain from doing this.

Brian Grunkemeyer
MS CLR Base Class Library team