0

Hi,

I'm working on a Generic Dictionary in C# and have came across a little problem with my add function.
My add function at the moment will take two inputs: Name and Age and then add them to the listBox associated with them.
What I'm trying to do is make the function accept another 3 entries, Height, Offences and Address but I've had no luck.

Currently I have this for my function:

 void AddBook(int isbn, string title, int Height)
        {
            criminals.Add(title, new Criminal(isbn, title));
        }

        private void Addbtn_Click(object sender, EventArgs e)
        {
            if (NameBox.Text != "" && AgeBox.Text != "" && HeightBox.Text != "")
            {
                if (AgeBox.Text.Length <= 3)
                {
                    ***if (HeightBox.Text.Length <= 5)
                    {
                        AddBook(int.Parse(AgeBox.Text), NameBox.Text, HeightBox.Text);***
                    }
                    else
                    {
                        MessageBox.Show("Age must be max 3 numbers in length");
                    }
                }
                else
                {
                    MessageBox.Show("Name Title and Age fields must be filled");
                }
                UpdateListBox();
            }
        }

The part in bold italic is where I have had a go at extending it myself.
I also have another class which ties in with this function:
Criminal.cs:

class Criminal
    {
        private int isbn;
        private string title;

        public Criminal(int isbn, string title)
        {
            this.isbn = isbn;
            this.title = title;
        }

        public int ISBN
        {
            get { return isbn; }
        }

        public string Title
        {
            get { return title; }
        }
    }
}

So, How can I achieve extending this function to take upto 5 inputs?

EDIT: On another note the isbn and title are used as I copied the coding from another program that acts as a library.
Also, The program is for Criminal Records.

Edited by Angelrawzz: Added Info

1
Contributor
1
Reply
18
Views
3 Years
Discussion Span
Last Post by Angelrawzz
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.