I have the following classes
Customer
Class
abstract class Customer
{
public int id;
public string name;
public double balance;
}
class NormalCustomer
class NormalCustomer: Customer
{
}
class SubscriberCustomer
class SubscriberCustomer:Customer
{
public int LandMinutes;
public int MobileMinutes;
}
If we create an array of Customers
Customer[] customers = new Customer[100];
customers[0]=new NormalCustomer();
customers[1] = new NormalCustomer();
customers[2] = new SubscriberCustomer();
customers[3] = new NormalCustomer();
customers[4] = new SubscriberCustomer();
The question is how do I know how many object in the array are NormalCustomers
and how many object in the array are SubscriberCustomers
?
You can use OfType extension method
customers.OfType<NormalCustomer>().Count()
You will need to import System.Linq
namespace with a using directive:
using System.Linq;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With