Re: A job for reflection? Or is there a better way?

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Gary Morris (gwmorris1_at_hotpop.com)
Date: 04/28/04


Date: Tue, 27 Apr 2004 22:12:49 -0400


> > OK, I don't actually have to have THE node name, I just want some way
> > of creating each instance of the tabpage with a unique name. Since I've
> > never had the need to do anything like this, I am looking for any
option.
>
> Objects don't necessarily *have* names. Usually I find when people want
> to give objects names, they're really after some way of retrieving an
> object by a string key later on. That's where hashtables come in
> useful.

What I'm wondering now is, when I create a tabpage will I not need to use
a member variable with the "TabPage somename = new TabPage();" type
of construct? That's what I am hung on. I did notice that I could use the
same "name" in an event (like a button or menu) and it will go ahead and
create a new control without any error, but does that not confuse things
later on? All of the new controls look like clones, so how do I determine
who
is what? How does the program know who is what? I hope that makes sense.

In other words:
You can't say "int i = new int()" but one time in any given scope or the
compiler complains about it and won't compile. Wouldn't the same hold true
for any member? If I have 5 tabpages all created with "TabPage newTab =
new TabPage()" will that actually work? This is what I am hung on more than
anything.

> > > I suggest you create the tab page and just put it in a Hashtable,
using
> > > the node name as the key.
> >
> > Never used a hashtable, though I've seen many programs and code
> > snippets that do use them. Maybe it's time to look into it....???
>
> That would be a good idea. I suggest you familiarize yourself with
> ArrayLists as well Hashtables before going much further - they're both
> pretty fundamental to writing many .NET applications. If you look up
> "collection classes" in the MSDN index, you'll see there's a tutorial
> and a couple of samples available. I haven't gone through them myself,
> but reading them (and/or a Collections chapter in a .NET book) would be
> a good idea.

I am familiar with both, just have never used them. I'm sure I've written
code
that would have benefited from one or the other, I just haven't seen the
need
until now!

And thanks for the quick reply. This could mean a good coding job for me if
I
can show that I know what I'm doing (and most of the time I do - I've been
programming since the Commodore, TI-994A, Atari XL, GWBASIC days). It
just sometimes overwhelms me, .NET is so huge.

> Jon Skeet - <skeet@pobox.com>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too


Quantcast