473,399 Members | 2,146 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,399 software developers and data experts.

what is wrong with this code?

I'm trying to write a class where I need to sort a list of TreeNode objects
in a certain way.

So I thought I'd use:

List<ListNodeData>

and then use the Sort method. I have the code working using SortedList
class, but its too slow since it sorts each time you insert. But just by
DECLARING the ListNodeData object, I get the infamous "exception has been
thrown by a target of an invocation" or whatever. I'm not even USING the
object and it throws an exception.

This is my ListNodeData class... it causes an exception by just being
defined in the namespace without even being used. Whats wrong with it?

public class ListNodeData : Object
{
public String strSortKey;
public TreeNode data;

public ListNodeData()
{
strSortKey = null;
data = null;
}

public override bool Equals(object obj)
{
if (obj.GetType() != this.GetType())
return false;
ListNodeData other = (ListNodeData)obj;
if ((other.strSortKey == strSortKey) && (other.data == data))
return true;
return false;
}

public override int GetHashCode()
{
return strSortKey.GetHashCode() ^ data.GetHashCode();
}

public override String ToString()
{
return data.ToString();
}

public ListNodeData Copy()
{
return (ListNodeData)MemberwiseClone();
}
}
Nov 17 '05 #1
1 1570
On Sat, 12 Nov 2005 02:42:44 -0800, "Nobody" <no****@cox.net> wrote:
I'm trying to write a class where I need to sort a list of TreeNode objects
in a certain way.

So I thought I'd use:

List<ListNodeData>

and then use the Sort method. I have the code working using SortedList
class, but its too slow since it sorts each time you insert. But just by
DECLARING the ListNodeData object, I get the infamous "exception has been
thrown by a target of an invocation" or whatever. I'm not even USING the
object and it throws an exception.

This is my ListNodeData class... it causes an exception by just being
defined in the namespace without even being used. Whats wrong with it?


Start with a completely empty class:

public class ListNodeData : Object
{
}

Compile and Run. If it fails then you have found your problem. If it
is OK then add a small piece of the class:

public class ListNodeData : Object
{
public String strSortKey;
public TreeNode data;
}

Compile and Run. If it fails then you have found your problem in the
bit you just added. If it is OK then add another a small piece of the
class. Repeat until you have either found the problem or got a
working copy of the class. Commenting out chunks of code works just
as well.

rossum
[snip code]

The ultimate truth is that there is no ultimate truth
Nov 17 '05 #2

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

Similar topics

125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
72
by: E. Robert Tisdale | last post by:
What makes a good C/C++ programmer? Would you be surprised if I told you that it has almost nothing to do with your knowledge of C or C++? There isn't much difference in productivity, for...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
51
by: WindAndWaves | last post by:
Can anyone tell me what is wrong with the goto command. I noticed it is one of those NEVER USE. I can understand that it may lead to confusing code, but I often use it like this: is this...
46
by: Keith K | last post by:
Having developed with VB since 1992, I am now VERY interested in C#. I've written several applications with C# and I do enjoy the language. What C# Needs: There are a few things that I do...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
1
by: GS | last post by:
I got a combobox box that I load at load time. the Item and vales ended up in reverse order of each other, what went wrong? the database table has the following row code value ebay ...
98
by: tjb | last post by:
I often see code like this: /// <summary> /// Removes a node. /// </summary> /// <param name="node">The node to remove.</param> public void RemoveNode(Node node) { <...> }
9
by: Pyenos | last post by:
import cPickle, shelve could someone tell me what things are wrong with my code? class progress: PROGRESS_TABLE_ACTIONS= DEFAULT_PROGRESS_DATA_FILE="progress_data" PROGRESS_OUTCOMES=
20
by: Daniel.C | last post by:
Hello. I just copied this code from my book with no modification : #include <stdio.h> /* count characters in input; 1st version */ main() { long nc; nc = 0;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.