Thread: DateTime.Now

  1. #1
    Registered User
    Join Date
    May 2006


    Hello everyone,

    Since DateTime is struct other than class, each time when we use DateTime abc = DateTime.Now, there are two copies of DateTime structs?


    One instance is created by DateTime struct internally, which represents the current time, and another instance is copied from the internal instance to the value type variable abc when we perform assignment operation?


    I think the internal instance is a waste? Since it is useless when the value is copied to variable abc?

    thanks in advance,

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    There's nothing internal, it's just a chunk of data (8 bytes unless mistaken).
    Not really much different than typing:
    int abc = int.MaxValue;
    (MaxValue being a constant rather than a property, but principle's the same)

    Unlike C++, a struct has not much in common with a class

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. checking input
    By deviousdexter in forum C# Programming
    Replies: 23
    Last Post: 12-19-2008, 04:20 PM
  2. out variable assignment
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 06-15-2008, 07:12 PM
Website Security Test