How do I cast List<SelectVacancyDetails_Result>
to List< SelectVacancyDetails_ResultExtend>
where class SelectVacancyDetails_ResultExtend
is inherited from class SelectVacancyDetails_Result
.
I tried below but no luck
List<SelectVacancyDetails_ResultExtend> vacExtList = vacList.Cast<SelectVacancyDetails_ResultExtend>().ToList();
(Basically i want all list properties value to be copied over)
If all the elements are actually of type SelectVacancyDetails_Result
(not SelectVacancyDetails_ResultExtend
) then you can't just cast. The simplest approach would be to create a constructor in SelectVacancyDetails_ResultExtend
which copied the properties - or just used composition instead of inheritance, potentially - and then you can use:
var vacExtList = vacList.Select(vac => new SelectVacancyDetails_ResultExtend(vac))
.ToList();
See more on this question at Stackoverflow