On Thu, 7 Aug 2008 00:49:22 +0100, Stuart Dunkeld <[EMAIL PROTECTED]> wrote: > >How about: > >Const c1FaLen = Convert.ToString(c1FullAddr).Length ?
As others have pointed out the compiler can't compile this, and it's simply another way of writing the orginal code that didn't compile. >Can I ask in the interest of increasing my understanding - where does >'compile time' come into it? There's code that's evaluated when it is compiled and there's code that's evaluated when it's run. The compiler can evaluate constant expressions. The compiler doesn't run code, it merely compiles it. When assigning to a const member, the value being assigned is evaluated when compiled and baked-in. Code that calls methods (or otherwise access non-const values) cannot be executed at compile-time (because they are not constant expressions) and thus can't be assigned to a const value. Could the compiler simply translate "text".Length into 4? If it knew what "Length" did, it could; but it currently doesn't know what Length does. It's currently ignorant of what properties and methods do, it simply knows what they are and how to emit IL that executes them at run- time. =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com