Ron

Ron

  • NA
  • 44
  • 64.4k

Basic class usage question

Jan 23 2012 12:18 PM
I'm having difficulty calling a class method and making use of its return value. This code is in the main cs file:

SomeApp.Players SomeAppPlayer = new SomeApp.Players();

private void Window_Loaded(object sender, RoutedEventArgs e)
{
*** Error here:   txtLastName.Text = SomeAppPlayer.GetPlayer();
}

In another class file is this code:

// This is in another file.

namespace SomeApp
{

    public class Players
    {
        public Player GetPlayer()
        {
            Player player = new Player("SMITH");
            return (player);
        }
    }

    public class Player
    {
        private string lastName;
        public string LastName
        {
            get { return lastName; }
            set { lastName = value; }
        }

        public Player(string lastName)
        {
            LastName = lastName;
        }
    }

}

I've omitted some code for simplicity, but when I step thru the code, everything seems to work ok. The problem is when I attempt to assign the return value to the text property of a textbox. This is the error I receive: Cannot implicitly convert type SomeApp.Player to type string.

I'm new to C#, and any guidance would be appreciated.

Answers (3)