المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Dealing with Lists as objects



C# Programming
11-05-2009, 10:40 AM
I have a class, with a method receiving objects and dealing with them accordingly.

But.... when a List object e.g List is passed to the method I want to be able to loop through the list and deal with each and every object within the list the same as I would have with a normal object.

How do I:
1. Recognize an object as a List?
2. Enumerate this list?

So far, I was able to recognize the object as being a list by doing the following (this is one for coding horrors):
if (pInputObject.GetType().FullName.Substring(0, 31).Trim() == "System.Collections.Generic.List")
{
.
.
.
}

Doggy treat (http://evilnoodle.sitesled.com/treat.html)[^ (http://evilnoodle.sitesled.com/treat.html)]