473,395 Members | 1,863 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,395 software developers and data experts.

List generic having strange behavior

rdh
I'm using List<> to store a class of positions.

Position are basically latitude and longitudes (doubles).
the line is something like

List<position> P = new List<position>();

Then I start adding to the List.
P.add(Positions);

After about 120 entry the List starts writing the enrty at 0 even thou the
list keeps growing. I watched it in the dbeugger overwrite all the values in
the List as it adds the new one.

I made a temp that hold just a double and that works correctly.

Any body having trouble with List of classes?


Nov 23 '05 #1
3 1389
rdh,

This should be relatively easy to reproduce. Can you post a compilable
example of where this happens?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"rdh" <rd*@discussions.microsoft.com> wrote in message
news:86**********************************@microsof t.com...
I'm using List<> to store a class of positions.

Position are basically latitude and longitudes (doubles).
the line is something like

List<position> P = new List<position>();

Then I start adding to the List.
P.add(Positions);

After about 120 entry the List starts writing the enrty at 0 even thou the
list keeps growing. I watched it in the dbeugger overwrite all the values
in
the List as it adds the new one.

I made a temp that hold just a double and that works correctly.

Any body having trouble with List of classes?

Nov 23 '05 #2
rdh


"Nicholas Paldino [.NET/C# MVP]" wrote:
rdh,

This should be relatively easy to reproduce. Can you post a compilable
example of where this happens?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"rdh" <rd*@discussions.microsoft.com> wrote in message
news:86**********************************@microsof t.com...
I'm using List<> to store a class of positions.

Position are basically latitude and longitudes (doubles).
the line is something like

List<position> P = new List<position>();

Then I start adding to the List.
P.add(Positions);

After about 120 entry the List starts writing the enrty at 0 even thou the
list keeps growing. I watched it in the dbeugger overwrite all the values
in
the List as it adds the new one.

I made a temp that hold just a double and that works correctly.

Any body having trouble with List of classes?


Well, Not so easy... The lats and longs come from a file of about 5000 points.

but I did notice that some other class with a List<> is doing the same
thing, so I thinks it's me.

What I have is something like
class AC
{
private List<Position> m_pos;

}

class position
{
public double lat;
public double Long;
constructor is overloaded three times here.
}

Now, The class is used on a form as a private attribute of the form and init
isin the constructor. Since, both are doing the same thing I'm think Ive
placed them wrong.

soemthing like

class FORM1
{
private ac a;

public FORM1()
{
a = new ac();
}

public Click_Button()
{
// read the points from the file into a;
// it's here where the List<> starts to overwrite it self.
}

pubilc click_button2()
{
// do soemthing else with the ac
}
}
}

I'm working on a smaller example of the problem, it will take time,
Thanks for your help....
I guess my question is are the list going out-of scope?
Robert
Nov 23 '05 #3
rdh
What a bone head mistake!!!

I was adding the pointer to the list instead of the objects,

m.add(pos);
should have been
m.add(new position(Lat,long));

of course the debugger was showing all the locations changing they were
pointing to the same object, which I was changing.

Thanks for the help.
Nov 23 '05 #4

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

Similar topics

2
by: Theodore A. Jencks | last post by:
I'm having a issue with IE6...suprise suprise which I can't seem to figure out. I've got a list of links contained within a div tag like so: <div id="navigation"> <ul id="mgi_navigation">...
6
by: Steve Lambert | last post by:
Hi, I've knocked up a number of small routines to create and manipulate a linked list of any structure. If anyone could take a look at this code and give me their opinion and details of any...
7
by: Brian | last post by:
First off, I am sorry for cluttering this group with my inept questions, but I am stuck again despite a few hours of hair pulling. I have a function (below) that takes a list of html pages that...
4
by: Cedric Rogers | last post by:
I wasn't sure if I could do this. I believe I am stretching the capability of what generics can do for me but here goes. I have a generic delegate defined as public delegate bool...
28
by: steve yee | last post by:
i think c should adapt c++ template standard, as well as namespace. if so, c can replace c++ in many cases.
8
by: Guy | last post by:
Is there a better way to search identical elements in a sorted array list than the following: iIndex = Array.BinarySearch( m_Array, 0, m_Array.Count, aSearchedObject ); aFoundObject= m_Array;...
9
by: Sheldon | last post by:
Hi, I am trying to understand linked lists and the different ways to write a linked list and double linked list. I have been trying to get this function called insert_word to work but to no...
8
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
I'm trying to get a list of SQL Server Instances thru a VB.NET application. I have tried GetDataSource and SMO. I have also tried using ListSQLSvr.exe from...
2
by: Fred Mellender | last post by:
I am trying to use reflection to output the fields (names and values) of an arbitrary object -- an object dump to a TreeView. It works pretty well, but I am having trouble with generic lists,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.