Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7970211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:21:44+00:00 2026-06-04T07:21:44+00:00

I have a static list: public static List<IMachines>mList =new List<IMachines>(); The list intakes two

  • 0

I have a static list:

public static List<IMachines>mList =new List<IMachines>();

The list intakes two different types of objects(machines) in it:

IMachines machine = new AC();
IMachines machine = new Generator();

If after adding items to the list, I want to search for a particular machine by its name property then after using the foreach loop for traversal if that item is found in list … how am I supposed to know if the item is of AC type or Generator type?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:21:45+00:00Added an answer on June 4, 2026 at 7:21 am

    Use the “is” operator.

    List<IMachines> list = new List<IMachines>();
    list.Add(new AC());
    list.Add(new Generator());
    foreach(IMachines o in list)
    {
      if (o is Ingredient)
      {
        //do sth
      }
      else if (o is Drink)
      {
        //do sth
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Generic List as below public static readonly List<Customer> Customers = new
I have an array list of objects in my application. private static ArrayList<Player> userList=new
I have this code : public static List<string> MyTable = new List<string>(); dsView =
I have this method public static List<SummaryItinerary> ReturnBookingsByUserGuid(Guid userGuid) { var entities = new
I have this code: public static List<ReplicableObject> ParseStreamForObjects(Stream stream) { List<ReplicableObject> result = new
I have the following snippet of code: public static List<string> sqlData = new List<string>();
I have this List: public static List<int> getData(OdbcConnection conn) { List<int> myData = new
For example I have: public static List<int> actorList = new List<int>(); public static List<string>
I have this bit of code, public static List<string> GetSentencesFromWords(List<string> words, string fileContents) {
i have the following code: public static void Serialize() { List<string> dirs = FileHelper.GetFilesRecursive(fileDirectoryPath);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.