Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Finding an instance of an object

Posted on 2008-10-14
4
Medium Priority
?
192 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

610 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