Question button is not showing the correct information

vivification

New member
Joined
May 6, 2013
Messages
1
Programming Experience
Beginner
Hi,

I have just started learning c# and I am trying to work out why my button is not showing the correct information.

Can someone please help.

The idea is that when the user clicks the Button on the form, it displays the following information on the dialog box.

newBook.AuthorName = "John Doe";
newBook.BookName = "C# 2008";
newBook.ReleaseDate = "2008";


newBook1.AuthorName = "Mary Doe";
newBook1.BookName = "C# 2010";
newBook1.ReleaseDate = "2010";

But it just displays a dialog box that says

Author:
Book:
Released:

Here is my Form1.cs
C#:
namespace WindowsFormsApplication1
{
    //form is intialised....
    //it will create 2 objects, NewBook and NewBook 1
    public partial class Form1 : Form
    {
        Book newBook = new Book();
        Book newBook1 = new Book();


        public Form1()
        {
            InitializeComponent();
        }


        //during the form load event those new Objects get loaded with some information.
        private void Form1_Load(object sender, EventArgs e)
        {          
            newBook.AuthorName = "John Doe";
            newBook.BookName = "C# 2008";
            newBook.ReleaseDate = "2008";


            newBook1.AuthorName = "Mary Doe";
            newBook1.BookName = "C# 2010";
            newBook1.ReleaseDate = "2010";
        }


        private void button1_Click(object sender, EventArgs e)
        {
            newBook.GetDetails();
            newBook1.GetDetails();
        }

Here is my Book.cs
C#:
namespace WindowsFormsApplication1
{
    class Book
    {


        public string BookName;
        public string AuthorName;
        public string ReleaseDate;
        public const string Publisher = "Microsoft";


        public void GetDetails()
        {
            MessageBox.Show("Author: " + this.AuthorName + "\n" +
                            "Book: " + this.BookName + "\n" +
                            "Released: " + this.ReleaseDate, "Details");


        }


    }
}
 
I just tested that exact code and it worked as expected for me so, if it's not working for you, either you're not using that exact code or something on your system is broken.
 
Back
Top Bottom