473,396 Members | 1,895 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Properties - multiple execution of get accessor code ?

In one of my test classes there is a code fragment like this:

protected System.Collections.Hashtable pData;
public System.Collections.Hashtable PData
{
get
{
//TODO: read PData from DB
System.Console.WriteLine("GET Hashtable");
return pData;
}
set { pData = value; }
}

In my test console application there is somethink like this:

Class1 test = new Class1();
System.Collections.Hashtable ht = test.PData;

Now, why do I get "GET Hashtable" 9 times !!! in the console when
debugging ? It seems that the code is really executed 9 times.

Why I tried this is I wanted to test behaviour of Properties when
using direct access like

test.PData.Add("Test", "A")

But then the whole app crashes.

Maybe you can tell me a little bit about my problem and the usage of
Properties.

Thanks,
Andre
Nov 16 '05 #1
3 1898
Andre Boeder <ne*@aboeder.com> wrote:
In one of my test classes there is a code fragment like this:

protected System.Collections.Hashtable pData;
public System.Collections.Hashtable PData
{
get
{
//TODO: read PData from DB
System.Console.WriteLine("GET Hashtable");
return pData;
}
set { pData = value; }
}

In my test console application there is somethink like this:

Class1 test = new Class1();
System.Collections.Hashtable ht = test.PData;

Now, why do I get "GET Hashtable" 9 times !!! in the console when
debugging ? It seems that the code is really executed 9 times.

Why I tried this is I wanted to test behaviour of Properties when
using direct access like

test.PData.Add("Test", "A")

But then the whole app crashes.

Maybe you can tell me a little bit about my problem and the usage of
Properties.


Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
I would guess you have something like 'test.PData' in your watch, which
means it gets re-executed every time you step to a new line, etc. If this
is the case, remove it from your watch window, or try running without
debugging.

"Andre Boeder" <ne*@aboeder.com> wrote in message
news:49**************************@posting.google.c om...
In one of my test classes there is a code fragment like this:

protected System.Collections.Hashtable pData;
public System.Collections.Hashtable PData
{
get
{
//TODO: read PData from DB
System.Console.WriteLine("GET Hashtable");
return pData;
}
set { pData = value; }
}

In my test console application there is somethink like this:

Class1 test = new Class1();
System.Collections.Hashtable ht = test.PData;

Now, why do I get "GET Hashtable" 9 times !!! in the console when
debugging ? It seems that the code is really executed 9 times.

Why I tried this is I wanted to test behaviour of Properties when
using direct access like

test.PData.Add("Test", "A")

But then the whole app crashes.

Maybe you can tell me a little bit about my problem and the usage of
Properties.

Thanks,
Andre

Nov 16 '05 #3
Thanks you are right - it is only a debugger problem.

But: why does

t.PData.Add("Test", "A") or something like this not work ?

If I write getters and setters by myself

t.getPData().Add("Test", "A") works fine.

Thanks very much
Andre

"Marina" <so*****@nospam.com> wrote in message news:<#H**************@TK2MSFTNGP11.phx.gbl>...
I would guess you have something like 'test.PData' in your watch, which
means it gets re-executed every time you step to a new line, etc. If this
is the case, remove it from your watch window, or try running without
debugging.

"Andre Boeder" <ne*@aboeder.com> wrote in message
news:49**************************@posting.google.c om...
In one of my test classes there is a code fragment like this:

protected System.Collections.Hashtable pData;
public System.Collections.Hashtable PData
{
get
{
//TODO: read PData from DB
System.Console.WriteLine("GET Hashtable");
return pData;
}

set { pData = value; }
}

In my test console application there is somethink like this:

Class1 test = new Class1();
System.Collections.Hashtable ht = test.PData;

Now, why do I get "GET Hashtable" 9 times !!! in the console when
debugging ? It seems that the code is really executed 9 times.

Why I tried this is I wanted to test behaviour of Properties when
using direct access like

test.PData.Add("Test", "A")

But then the whole app crashes.

Maybe you can tell me a little bit about my problem and the usage of
Properties.

Thanks,
Andre

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Terry Hancock | last post by:
Frankly, I was surprised this worked at all, but I tried creating a property outside of a class (i.e. at the module level), and it seems to behave as a property: >>> def get_x(ob): .... ...
10
by: Jeff Grills | last post by:
I am an experienced C++ programmer with over 12 years of development, and I think I know C++ quite well. I'm changing jobs at the moment, and I have about a month between leaving my last job and...
0
by: liko81 | last post by:
I have an Invoice class that must know, directly or indirectly, how to do anything associated with creating, reading, or otherwise processing an invoice to a customer. It is an uber-DAO object that...
26
by: optimistx | last post by:
A variable in global scope var a1 = 'contents of global variable a1'; can be references (with some limitations) as window; // or window.a1; // or even window;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.