Make a class named Fruit with a data member to calculate the number of fruits in a basket. Create twoother class named Apples and Mangoes to calculate the number of apples and mangoes in the basket.Print the number of fruits of each type and the total number of fruits in the basket. c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
static void Main()
{
List<Fruit> basket = new List<Fruit>()
{
new Apple(),
new Apple(),
new Mango()
};
Console.WriteLine($"Count of Fruits: {basket.Count}");
Console.WriteLine($"Count of Apples: {basket.OfType<Apple>().Count()}");
Console.WriteLine($"Count of Mangoes: {basket.OfType<Mango>().Count()}");
}
class Fruit
{
}
class Apple : Fruit { }
class Mango: Fruit { }
}
Comments
Leave a comment