Cannot implicitly convert type ‘customtype’ to ‘othercustomtype’

Because a Person is not nessecarily a User, the compiler is not able to implicitly convert a Person to a User. In your particular case, since you know you have a list of Users, you can explicitly tell it, “I know this Person is actually a User” with the following:

if (person != null)
   return (User) person;

The cast ((User)) will throw an exception at runtime if the instance is not actually a User, but since you’ve started with a collection of Users to begin with, you don’t need to worry.

Leave a Comment