Are Unused Constants Optimized away? If not, how to?

I’m cross posting this question I asked on stack overflow and haven’t gotten a complete answer just yet. I thought I might bring it here:

[url]c# - Are unused constants still compiled or optimized away? If not, how to accomplish? - Stack Overflow

Basically, I’m trying to make some sort of constants class(or whatever) and want to know if there’s a way to optimize out the unused constants when it’s compiled and deployed.

use enum


enum registers {
  Tim9 = 0x40014000,
  Tim8 = 0x40010400,
 etc.....
}

I’d be shocked if unused enum values were optimized out any more than constants (and I’d be shocked if they were optimized out). In general, I doubt they’d result in any significant savings IL-size-wise over constants, either. At the end of the day, your IL size here is going to be mostly related to how long the names are, and how many bytes it takes to store the values, either way you go.

Is there a way in Visual Studio to check the compiled file size of what’s deployed to the device?