Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

how to iterate a generic list in c#

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

    foreach (V element in myList)
    {
      //This will now work because you've constrained the generic type V
      Guid test = element.IetmGuid;
    }
  }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #iterate #generic #list
ADD COMMENT
Topic
Name
8+8 =