Thread: DateTime.Now

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    DateTime.Now

    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?

    1.

    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?

    2.

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


    thanks in advance,
    George

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    There's nothing internal, it's just a chunk of data (8 bytes unless mistaken).
    Not really much different than typing:
    Code:
    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
    MagosX.com

    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, 05:20 PM
  2. out variable assignment
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 06-15-2008, 07:12 PM