473,666 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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<ListNodeDa ta>

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)o bj;
if ((other.strSort Key == strSortKey) && (other.data == data))
return true;
return false;
}

public override int GetHashCode()
{
return strSortKey.GetH ashCode() ^ data.GetHashCod e();
}

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

public ListNodeData Copy()
{
return (ListNodeData)M emberwiseClone( );
}
}
Nov 17 '05 #1
1 1587
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<ListNodeD ata>

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
14706
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 software giant such as Microsoft SQL Server, Oracle, and Sybase? Is PostgreSQL reliable enough to be used for high-end commercial application? Thanks
72
5833
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 example, between a C/C++ programmers with a few weeks of experience and a C/C++ programmer with years of experience. You don't really need to understand the subtle details or use the obscure features of either language
121
10028
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 support IDEs are DreamWeaver 8 and Zend PHP Studio. DreamWeaver provides full support for Unicode. However, DreamWeaver is a web editor rather than a PHP IDE. It only supports basic IntelliSense (or code completion) and doesn't have anything...
51
13349
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 wrong????? Function x select case z
46
4198
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 believe MSFT should do to improve C#, however. I know that in the "Whidbey" release of VS.NET currently
13
5035
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
1461
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 http://www.ebay.com google http://www.google.com yahoo http://www.yahoo.com However in the drop down list displayed value used ebay http://www.yahoo.com
98
4568
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
2118
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
2807
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
8871
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8551
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8640
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7386
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2771
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1776
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.