Solved

Finding an instance of an object

Posted on 2008-10-14
4
183 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Login 17 50
how to change the view engine in visual studio 2015 enterprises edition 7 42
C# bracket error 3 30
Switching Visual Studio 2015 to normal debug display 3 25
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

785 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