c# - Returning an enumeration of events on particular date -


i trying write function returns enumeration of 'appointment' items consists of following code -

public interface iappointment {     datetime start { get; }     int length { get; }     string displayabledescription { get; }     bool occursondate(datetime date); } 

the function supposed retrieve 'appointments' items out of list. have instanced list @ top of class accessed globally methods implemented ilist interface.

here function far

public ienumerable<iappointment> getappointmentsondate(datetime date) {     foreach (iappointment item in _list)     {         if(item.start.date == date.date)         {             return item; //  error appears here under 'item'         }     } } 

error:

cannot implicitly convert type '....iappointment' 'system.collections.generic.ienumerable<...iappointment>'. explicit conversion exists (are missing cast?)

this assignment spec function: getappointmentsondate - retrieves enumeration of of appointments occur on specified date.

use yield keyword:

public ienumerable<iappointment> getappointmentsondate(datetime date)     {          foreach (iappointment item in _list)         {             if(item.start == date)             {                 yield return item;               }         }      } 

or use achieve condition (don't forget include import system.linq;):

_list.where(item=>item.start == date); 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -