The Pragmatic Programmer

Tulisan iseng kalo ada waktu.
See also: Other Geeks@INDC

Just a moderate question

Let's say you have this solution structure:

Solution 'ConsoleApplication2' (2 projects)
|- ClassLibrary1
|  |- Class1.cs
|
|- ConsoleApplication2
   |- Program.cs


In Class1.cs, you define:

namespace ClassLibrary1
{
    
    public class Class1
    {
        public const int ItemPrice = 500;
    }
}

In Program.cs, you define:

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        
        {
            Console.WriteLine(ClassLibrary1.Class1.ItemPrice * 2);

            Console.ReadLine();
        }

    }
}


You have deployed your ConsoleApplication2 application into two different PCs.
Now, you change the value of ItemPrice constants into 1000 and then you compiled the ClassLibrary1 library.

How do you deploy the changes to the two PCs?
Do you just need to deploy the ClassLibrary1 assembly or else?
And why?

Share this post: | | | |

Comments

Jimmy Chandra said:

constants will get optimized to value.

In this case, it's even worse 500 * 2 will be optimized to 1000 inside ConsoleApplication2.exe.

As proven by Reflector:

private static void Main(string[] args)

{

   Console.WriteLine(0x3e8);

   Console.ReadLine();

}

Changing it to public static readonly int ItemPrice = ....; should make that deployment scenario work just fine.

:-)

Reflector does it things again:

private static void Main(string[] args)

{

   Console.WriteLine((int) (Class1.Silly * 2));

   Console.ReadLine();

}

Bugs like this will give you a headache, luckily there is Reflector.

# April 16, 2008 11:09 AM