We help IT Professionals succeed at work.

is 'design time' same as 'compile time' in C#?

IzzyTwinkly
IzzyTwinkly asked
on
Hi,

I am reading a C# book.  it refers 'desgin time', like 'A class in design time is just data type, so it doesn't have any memory assigend yet.'
is 'design time' same as 'compile time'?  

Thanks~
Comment
Watch Question

Guy Hengel [angelIII / a3]Billing Engineer
Most Valuable Expert 2014
Top Expert 2009
Commented:
in regards to that definition: yes. at compile time, the c# code is compiled into machine code (.exe/.dll), and the memory used to compile is only for the class definition, not an object's memory.

only if later the code actually runs at this line:

MyClass c = new MyClass();

Open in new window


then the object c get's initiated with the memory need to hold all of the data structures for MyClass.
Generally any program won't occupy the memeory until it's getting execute / called

Similarly
If you decalre an variable in C# as

int a;

doesn't allocate memory until the call to first assignment raise

a=10;  
Once the execution fo code by CLR reaches the code fro assignment then the CLR will identify the Datatype and get the size of the type to allocate the memory for the varaible.

Author

Commented:
Hi
thanks for your replies.
so in C# 'design time' and 'compile time' are equivalent?
Yes,  
Memory allocation will happen only at runtime.
Design time has nothing to do with compiling. The real distinction relating to design time is runtime. Those are the two distinctions you'll come across, especially when designing controls.

Look up "design time versus runtime". The very first topic from MS talks about WPF controls at design time.

When in Visual Studio, your code can execute and therefore will be instantiated. It will consume memory. It's real, living code!

The issue that frequently comes up, which is why the term even exists, is that your code often needs to know if you're in design mode (Visual Studio, dragging things around, resizing forms, etc.). Your code can check this and behave accordingly.  .net is a JIT environment. When you are working with custom controls, they are compiled and running right there, long before you hit F5 to start debugging!