Well, if you want to be able to pass a generic list, then I guess you
are talking about a generic method - i.e.
public void SomeMethod<T>(IList<Tlist) {...}
In which case, the answer is typeof(T). If you mean just "a
list" (IList, not IList<T>), then a lot of the standard framework code
is based around inspected the int-indexer. For example, the code below
resolves that the list is a string-list. In the absense of a non-
object int-indexer (i.e. no indexer, or it is just typed as object),
the framework code takes the first (zeroth) element.
There is one other special case worth mentioning; the data-binding
code also respects ITypedList, which tells you about properties of the
list items - this mainly applies to flexible runtime things like
DataTableView.
Marc
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
static class Program
{
static void Main()
{
IList list = new List<string>();
PropertyInfo prop =
list.GetType().GetProperty("Item", new Type[]
{ typeof(int) });
if (prop != null)
{
Console.WriteLine(prop.PropertyType.Name);
}
}
}