Cannot implicitly convert type 'customtype' to 'othercustomtype'

前端 未结 5 850
鱼传尺愫
鱼传尺愫 2020-12-06 17:25

I am new to C#. I have a Persons class and a User class which inherits from the Persons class. I my console I input a users in an array. Then I can add a note to a user that

5条回答
  •  -上瘾入骨i
    2020-12-06 18:05

    Anyway, I recommend to use LINQ extension method for your first method:

    using System.Collections.Generic;
    using System.Linq;
    
    public static Persons FindPerson(IEnumerable persons, int id)
    {
        return persons.FirstOrDefault(p => p.ID == id);
    }
    

    Looks much better, right?

提交回复
热议问题