Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert type string to type object

Tags:

c#

I am new to C#. I need to show a users fullname in a console application, but I keep getting this error

Cannot implicitly convert type 'string' to 'UserCustomerNotes.User'

My code works when I only use return user but all that it shows in the app then is "UserCustomerNotes.User" and I need to show the fullname of the user. Can anyone please help. Here is my code:

public static User FindUser(User[] users, int noteid)
{
    foreach (User user in users)                
        if (user.ID == noteid) return user.FullName;
    return null;
}
like image 490
CSharpSuzie Avatar asked Dec 13 '25 04:12

CSharpSuzie


1 Answers

Your method excpecting a return value of typeUser, if you want it to return name - change it to:

public static **string** FindUser(User[] users, int noteid)

or, alternatively:

if (user.ID == noteid) return user;
like image 152
Nissim Avatar answered Dec 14 '25 17:12

Nissim