Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1018061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:48:01+00:00 2026-05-16T10:48:01+00:00

I am new to C#. I need to show a users fullname in a

  • 0

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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:48:01+00:00Added an answer on May 16, 2026 at 10:48 am

    Your code:

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

    Is expecting to return a string object (the user.FullName value) when it succeeds in finding one, whereas the return type you’ve declared for your method is User. What you should do is this (where you’re currently calling FindUser:

    var ArrayOfUsersToSearch = GetAnArrayOfUserFromSomewhere();
    var noteId = 3; // Or whatever value you want to use
    var myUserToFind = FindUser(ArrayOfUsersToSearch, noteId);
    
    Console.WriteLine("The users full name is: {0}", 
            myUserToFind != null ? myUserToFind.FullName : "Not Found");
    

    And change the code in your FindUser method to be:

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

    The reason you see “UserCustomerNotes.User” output when you return user from your method is this:

    Console.WriteLine(FindUser(users, noteId));
    
    // instead of
    
    Console.WriteLine(FinderUser(users, noteId).FullName);
    

    Because the return type is UserCustomerNotes.User and it doesn’t have an override of “ToString” to specify anything different, the default value that is given when Console.WriteLine asks your User object for its textual equivalent is its name. This explains why you see the “odd” output from your code currently.

    Note: I’ve put Console.WriteLine("The users full name is: {0}", myUserToFind != null ? myUserToFind.FullName : "Not Found"); as your code can return null if it fails to find a user and you’d want to special-case the output you provide in that circumstance.

    It’s also worth mentioning, but unrelated to the question itself, that the format:

    foreach(var x in y)
        do something;
    

    Can be more prone to “breaking” if changes are made further down the line than if you explicitly call out the { and } around each statement block:

    foreach (User user in users)                
    {
        if (user.ID == noteid) 
        {
            return user.FullName;
        }
    }
    return null;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following Hartl's RailTutorial for Rails(3.2). I keep getting this error message or oddly a
I need to generate report that will show number of new / changed rows
I need to create a new Hash object using two arrays. But, the conditions
I'm writing a new Java 6 Swing application and want to have a Show
I've been working on a WPF application and need to be able to show
I need to show multiple buttons, but each one must have a different background
I need to provide users with the ability to hide/show table columns. Using previous
So there is record.new_record? To check if something is new I need to check
For a new project I need to load big XML files (200MB+) to a
In my app, I need every new record to be added to the index

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.