日期:2014-05-18  浏览次数:20426 次

高手请进,想获得一个不确定泛型List<T>的所有子集,该怎么实现?
研究半天未果。

List <xxxxx>   abc   =   new   List <xxxxx> ;
OutPut(abc);

---------------------

void   OutPut(object   o)
{
object   o;
System.Type   t   =   o.GetType();
string   tmp   =   t.ToString();
if   (tmp.IndexOf( "System.Collections.Generic.List ")   !=   -1)
{
      string   t2Str   =   tmp.Substring(tmp.IndexOf( "[ ")   +   1,   tmp.IndexOf( "] ")   -   tmp.IndexOf( "[ ")   -   1);

      System.Type   t2   =   Type.GetType(t2Str);
      List <object>   os   =   (List <object> )o;

      foreach   (object   o2   in   (System.Collections.ArrayList)o)
      {
          ......
      }
}
}
本来打算这么做,不过List <xxxxx> 不能转换成List <object> ,So   ?

------解决方案--------------------
晕 那还不如直接用arraylist
------解决方案--------------------
List <object> os = (List <object> )o;

foreach (object o2 in (System.Collections.ArrayList)o)
{
......
}
------------------》这样就可以吧
//List <object> os = (List <object> )o;

foreach (object o2 in o)
{
......
}
------解决方案--------------------
晕 看错了。。。
------解决方案--------------------
范型就是为了确定类型,
------解决方案--------------------
up
------解决方案--------------------
函数改成这样就可以了
void OutPut(IList o)
------解决方案--------------------
void OutPut(IList o)
{
System.Type t = o.GetType();
string tmp = t.ToString();
if (tmp.IndexOf( "System.Collections.Generic.List ") != -1)
{
string t2Str = tmp.Substring(tmp.IndexOf( "[ ") + 1, tmp.IndexOf( "] ") - tmp.IndexOf( "[ ") - 1);

System.Type t2 = Type.GetType(t2Str);

foreach (object o2 in o)
{
...
}
}
}
------解决方案--------------------
管它娘的 先存进去 取时再做处理
------解决方案--------------------
泛型是对类型的抽象,

在实例化的时候,必须要传入一个确定类型.
你哪里来的不确定泛型?

什么意思啊?