what is watch window really showing

N

Neil

Hi,

If I have the code line "DateTime d1 = DateTime.Now;" and
look at d1 in the watch window, I thought I'd only see the
properties of the DateTime object variable d1.

However I seem to be seeing lots of other properties and
objects - can anyone explain what these are and where they
come from?

i.e. the watch window column headings are Name/Value/Type,
and I see some of the following (6 items given) -

+System.ValueType {System.DateTime} System.DateTime - an
object
+Date (9/9/2004) System.ValueType - an other object
DatePartDay 3 int
....
Day 9 int - this is a DateTime property, so I understand
where it has come from :)
DayOfWeek Thursday System.DayOfWeek
....
+DaysToMonth365 {lenght=13} int[] - yet another object
....

Can anyone shed any light on where these 5 out of the 6
above come from?

I also tried to declare a variable for DatePartDay
via "int i = d1.DatePartDay;" in code but get the compile
error "'System.DateTime.DatePartDay' is inaccessible due
to its protection level"

TIA, Neil.
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi Neil,

The Watch window shows all private, protected and internal members in
addition to the public ones. Obviously, the DateTime type has a number or
private members, so you see them in the Watch window.
 
G

Guest

Hi Dmitriy,

Thanks for the reply. Still a bit stumped though!

How do I find these members then? The Class Library for
the System.DateTime structure off MSDN gives me the public
members, but where are the ones you mention? How do they
get "attached" to the DateTime structure?

They can be viewed in the watch window, but never
displayed eg from my original post "int i =
d1.DatePartDay;" but get a compile error - how come?

Thanks, Neil.
-----Original Message-----
Hi Neil,

The Watch window shows all private, protected and internal members in
addition to the public ones. Obviously, the DateTime type has a number or
private members, so you see them in the Watch window.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

Neil said:
Hi,

If I have the code line "DateTime d1 = DateTime.Now;" and
look at d1 in the watch window, I thought I'd only see the
properties of the DateTime object variable d1.

However I seem to be seeing lots of other properties and
objects - can anyone explain what these are and where they
come from?

i.e. the watch window column headings are Name/Value/Type,
and I see some of the following (6 items given) -

+System.ValueType {System.DateTime} System.DateTime - an
object
+Date (9/9/2004) System.ValueType - an other object
DatePartDay 3 int
...
Day 9 int - this is a DateTime property, so I understand
where it has come from :)
DayOfWeek Thursday System.DayOfWeek
...
+DaysToMonth365 {lenght=13} int[] - yet another object
...

Can anyone shed any light on where these 5 out of the 6
above come from?

I also tried to declare a variable for DatePartDay
via "int i = d1.DatePartDay;" in code but get the compile
error "'System.DateTime.DatePartDay' is inaccessible due
to its protection level"

TIA, Neil.

.
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi Neil,

These are private or protected members. They are not documented, nor they
are shown by Intellisense - since you should know nothing about their
existence and purpose. In other words, these are members used internally by
the class, but which are not intended to be used outside the class. It's
what is called 'encapsulation' in the OOP world.

Such members are shown in the Watch window solely for debugging purposes so
you could examine the internal state of a class without having to add
individual class members.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top