TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
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.
Reply
Answers (
3
)
Generate serial no in C#
Help with GUI#2