Hi
Try to change that in that way :
public int SearchDog(List<Animal> animal, string sClassName)
...
if ((animal[i] as Type).Name.Equals(sClassNa
// do something
Regards
Daniel
How do I change the following code to instead of just having animal as an inparameter I want the class as inparameter as well.
So instead of
public int SearchDog(List<Animal> animal)
i want
public int SearchDog(List<Animal> animal, String className)
Sow where it says Dog I want to put className as inparameter.
That means I can search the class I want. Is there away to do that?
I know String className wont work. What should it be instead of STRING?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
DanSo1 - your solution is an option (this is a method of reflection) but why not just pass in a Type class as a parameter if you want to do it that way:
public int SearchFor<T, C>(List<T> list)
where T : class, C : class
{
...
if (list[i].GetType().Equals(
// do something
...
}
Also, if you are going to use string comparisons then it would be better to use the AssemblyQualifiedName as this is a true check that the object is of the specified type.
Also, one further point that applies to both solutions offered so far.
The "is" keyword checks for assignment compatibility (see http://msdn.microsoft.com/
Well I dont get it to work.
Look here:
when I call it I need to call it like this to make it build
Search<Animal>(animalList) + 1;
but what I am after is that it would be something like this
Search<Dog>(animalList) + 1;
For example. If I want to find Dogs in my animal list I need to send in the class I am looking for. So what I am doing wrong?
the error if I change to : Search<Dog>(animalList) + 1;
Error 1 The best overloaded method match for 'Modul1_Malmoe.Code.Animal
This one: if (searchedType.IsAssignable
gets:
Error 1 The best overloaded method match for 'System.Type.IsAssignableF
Error 2 Argument '1': cannot convert from 'T' to 'System.Type' C:\Documents and Settings\MFL\Dokumenter\Vi
Business Accounts
Answer for Membership
by: SteveH_UKPosted on 2009-06-15 at 05:33:40ID: 24628174
You can do this in one of two ways. For most purposes, you should use a templated method, shown below.
You can also do something more sophisticated with reflection if that is what you need.
Select allOpen in new window