📜  如何在 c# 代码示例中迭代通用列表

📅  最后修改于: 2022-03-11 14:48:52.499000             🧑  作者: Mango

代码示例1
public class MyGenericClass
  where V : Item  //This is a constraint that requires type V to be an Item (or subtype)
{
  public void DoSomething()
  {
    List myList = someMethod();

    foreach (V element in myList)
    {
      //This will now work because you've constrained the generic type V
      Guid test = element.IetmGuid;
    }
  }
}