You can only use yield return
in a function that returns an IEnumerable
or an IEnumerator
, not a List<T>
.
You need to change your function to return an IEnumerable<DesktopComputer>
.
Alternatively, you can rewrite the function to use List<T>.ConvertAll
:
return GetComputerIdTags().ConvertAll(pcTag =>
new DesktopComputer() {
AssetTag = pcTag,
Description = "PC " + pcTag,
AcquireDate = DateTime.Now
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…