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

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'