将类型字符串转换为类型对象

CSh*_*zie 3 c#

我是C#的新手.我需要在控制台应用程序中显示用户fullname,但我一直收到此错误

无法将类型'string'隐式转换为'UserCustomerNotes.User'

我的代码只在我使用时工作,return user但它在应用程序中显示的所有内容都是"UserCustomerNotes.User",我需要显示用户的全名.谁能请帮忙.这是我的代码:

public static User FindUser(User[] users, int noteid)
{
    foreach (User user in users)                
        if (user.ID == noteid) return user.FullName;
    return null;
}
Run Code Online (Sandbox Code Playgroud)

Nis*_*sim 9

您的方法要求返回值为typeUser,如果您希望它返回名称 - 将其更改为:

public static **string** FindUser(User[] users, int noteid)
Run Code Online (Sandbox Code Playgroud)

或者,或者:

if (user.ID == noteid) return user;
Run Code Online (Sandbox Code Playgroud)