Enumerating through instances of derived class instances



if have numerous instances of different derived classes (with classes derived same base class), how might possibly enumerate through them, besides them being in list?

 

to enumerate them, need in collection.


if want use instances, "easiest" method typically make array:

  foreach(var item in new baseclass[] {instance1, instance2, instance3}) {    // use item }  


if you're making method, can use iterators:

  ienumerable<baseclass> getenumerator() {    yield return instance1;    yield return instance2;    yield return instance3; }  



reed copsey, jr. - http://reedcopsey.com
if post answers question, please click "mark answer" on post , "mark helpful".


Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

RFC_ERROR_SYSTEM_FAILURE with SAP ECC 6 Unicode

C# System.Data.Common DbCommand and getting Datasets from Oracle