Results 1 to 2 of 2

Thread: == operator question...

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    == operator question...

    Hello,

    Good Morning!!!

    I have created a product class (base class) and two sub classes (derived classes) called Books and DVD's (that inherit, from Product base class).

    I was able to load both books and dvd objects into an array list and I loaded the contents of the array list into a list box control in the Load event of the form.

    So far so good. I have provided to radio buttons (Books only, DVD's Only) on the same form. If the user chooses "Books only" radio button, then only the books objects should be populated in the list box (after clearing all the content of the list box)

    So I was planning to use GetType method of system.object class to determine what kind of objects in the arraylist (that I have loaded in form_load event) .

    can some one help me with the syntax.

    I tried :

    Type t = allProducts.GetType();

    foreach(object k in allProducts)
    {
    if (rdoBooks.Name == t.GetType().Name)
    {
    lst.Add.Items.Add(k._code)

    }
    }

    though t.GetType().Name has "Books" and the rdoBooks.Name is Books in the Immediate window, some how the lst.Add.Items.Add(k._code) doesn't get executed. why is the condition not True?

    thanks
    nath

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,449

    Re: == operator question...

    Books only:
    Code:
    foreach (Product prod in allProducts)
    {
        if (prod.GetType() == typeof(Book))
        {
            MessageBox.Show("prod is a Book.");
        }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width