|
-
Apr 20th, 2006, 01:34 AM
#1
Thread Starter
Hyperactive Member
== 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
-
Apr 20th, 2006, 01:43 AM
#2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|