How can i get a object by it name in the class whict create it.

@

@@Worker

for example,i create a class as below

public class testClass{
private object obj //this is the right object i need
public testClass(){
obj = new object();
}
public object GetObj(string name){
return this.XXXXX(name);// now how can i get the object with the
name
}
}

thanks for ur help.

eugene, china
2006-5-18
 
S

Stoitcho Goutsev \(100\)

It looks like you are asking for .NET Reflection, but what exactly is
this.XXXXXX. Can you please elaborate a bit.
 
J

james.curran

public class testClass{
private object obj1;
private object obj2;
private Hashtable ht;
public testClass()
{
obj1 = new object();
obj2 = new object();
ht = new Hashtable();
ht["obj1"] = obj1;
ht["obj2"] = obj2;
}
public object GetObj(string name)
{
return ht[name]
}
}
 
G

Guest

public class testClass{
private object obj //this is the right object i need
public testClass(){
obj = new object();
}
public object GetObj(string name){

switch ( name )
{
case "obj" : return ( this.obj ) ;
..
..
..
default : throw ...
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top