Solved

Finding an instance of an object

Posted on 2008-10-14
4
181 Views
Last Modified: 2010-04-15
I have used :
Button btn = (Button)this.Controls.Find("button" + strLetter.ToUpper(), true) [0];
to find a control named button.a

How would I find an instance of a class that I have created named myIHCPanelA.
This is not a control so I can't do this:
Specimen sp = (Specimen)this.Controls.Find("myIHCPanel" + strLetter.ToUpper(), true)[0];
0
Comment
Question by:urologic
  • 2
  • 2
4 Comments
 
LVL 13

Expert Comment

by:crazyman
ID: 22712461
When you say 'find an instance of a class', when you create the instance you should have a reference to it, when your instance goes out of scope or you explicitly dispose of it then it will be garbage collected and will no longer exist, so generally speaking if you dont have a reference to it and need to 'find' it then it wont even exist for you to find.
0
 

Author Comment

by:urologic
ID: 22712862
Thanks for the reply.

The instance isn't out of scope, I created it just after loading my form. What I am doing is iterating through a recordset and when I find the line that references specimenA (strLetter) I need to the populate myIHCPanelA.name, myIHCPanelA.description, etc. for several specimens a-x.
0
 
LVL 13

Accepted Solution

by:
crazyman earned 500 total points
ID: 22713281
i see.

Can you not add them to a dictionary...

Dictionary<string,YourType> dict = new Dictionary<string,YourType>();


dict.add("A",instance);
dict.add("B",instance);
dict.add("C",instance);



then ref them via
dict["A"]

etc...
0
 

Author Comment

by:urologic
ID: 22713578
Thanks. I will give that a try.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now