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 3459060
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:03:37+00:00 2026-05-18T10:03:37+00:00

I have a method named ‘PersonsMeeting’ that gets as parameter ObservableCollection of Person. Can

  • 0

I have a method named ‘PersonsMeeting’ that gets as parameter ObservableCollection of Person. Can I somehow deliver it an ObservableCollection of Employee ? what casting do I need ?

p.s – I don’t want to get rid of the ObservableCollection type in the method since I’m using it’s functionality.

public partial class MainWindow : Window
{
    public ObservableCollection<Employee> Emp { get; set; }

    public MainWindow()
    {
        Emp = new ObservableCollection<Employee>();

        InitializeComponent();
        PersonsMeeting(Emp); // How Do I Cast this ?!?!?!??
    }

    private void PersonsMeeting(ObservableCollection<Person> persons)
    {
        // ....
    }
}

public class Person{}
public class Employee : Person{}
  • 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-05-18T10:03:38+00:00Added an answer on May 18, 2026 at 10:03 am

    Since you already know that every Employee is a Person, you can simply use Enumerable.Cast to cast the elements to the type needed:


    PersonsMeeting(Emp.Cast());

    PersonsMeeting(new ObservableCollection<Person>(Emp.Cast<Person>()));
    

    But this will most likely not produce the results you expect since you’re really creating a new ObservableCollection rather than utilizing the existing one.

    Update 2

    I notice that the PersonsMeeting method is private and that you’re only ever calling it with an ObservableCollection<Employee>.

    If that’s the case, then you’re trying to use an unnecessary abstraction in your private method. You can safely get rid of that and simply modify PersonsMeeting to take an ObservableCollection<Employee>.

    The other option is to change the way your class is exposing its data. If you want to keep the abstraction, make your class look like:

    public partial class MainWindow : Window
    {
        private ReadOnlyObservableCollection<Person> _readOnlyEmp = null;
        private ObservableCollection<Person> _emp = new ObservableCollection<Person>;
    
        public ReadOnlyObservableCollection<Person> Emp
        {
            if(_readOnlyEmp = null)
                _readOnlyEmp = new ReadOnlyObservableCollection<Person>(_emp);
    
            return _readOnlyEmp;
        }
    
        public void AddEmployee(Employee e)
        {
            _emp.Add(e);
        }
    
        public void RemoveEmployee(Employee e)
        { 
            _emp.Remove(e);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Welcome! I have a recursive public static method named less that takes a tree
I have a log method which saves to a file that is named the
Let's say I have a structure named vertex with a method that adds two
I have an object with a method named StartDownload() , that starts three threads.
I have a method named InitializeCRMService() which returns an object of IOrganizationService . Now
I have a method named RenderContent which returns object[] In my unit test, I
I have two class files hudlayer.m and actionlayer.m I have a method named jump
I have a Silverlight control with a method named DoSomething() decorated with the <ScriptableMember()>
I have a custom class named CatalogItem which I receive in a method, as
I have method that returns module path of given class name def findModulePath(path, className):

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.