---
title: "A simple question about overloading"
url: "https://osherove.com/blog/2005/1/5/a-simple-question-about-overloading.md"
canonical: "https://osherove.com/blog/2005/1/5/a-simple-question-about-overloading.html"
published: "2005-01-05T22:49:00"
updated: "2005-01-05T22:49:00"
tags: [".Net Original"]
author: "Roy Osherove"
description: "Given 3 classes: PersonBase, Employee and Manager: class PersonBase { } class Employee : PersonBase { } class Manager : Employee { } and given the following methods: public void Loop() { PersonBase [] people = new…"
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# A simple question about overloading

By Roy Osherove January 5, 2005 In [.Net Original](https://osherove.com/blog/category/net-original)

**Historical article** · Originally published January 5, 2005; technical details may be outdated.

Given 3 classes: PersonBase, Employee and Manager:

class PersonBase { }

class Employee : PersonBase { }

class Manager : Employee { }

and given the following  methods:

public void Loop()

 {

     PersonBase\[\] people = new PersonBase\[\]{

                                 new PersonBase(),

                                 new Employee(),

                                 new Manager()

                                 };

     foreach (PersonBase pb in people)

     {

         doSomething(pb);

     }

 }

 void doSomething(PersonBase p)

 {

     Console.WriteLine("PersonBase");

 }

 void doSomething(Employee e)

 {

     Console.WriteLine("Employee");

 }

 void doSomething(Manager m)

 {

     Console.WriteLine("Manager");

 }

Why does only the first of the three “doSomething” overloads get called for all the objects in the array?

How could you force those methods to get called?

_(Ignore the various class factory solutions out there.)_

## More in .Net Original

[All posts in .Net Original](https://osherove.com/blog/category/net-original)

- Jan 7, 2005

    ### [Using Regex to return the first N words in a string](https://osherove.com/blog/2005/1/7/using-regex-to-return-the-first-n-words-in-a-string.html)

- Jan 6, 2005

    ### [Return of the Extensibility Application Block](https://osherove.com/blog/2005/1/6/return-of-the-extensibility-application-block.html)

- Dec 31, 2004

    ### [Manage many events easily with EventHandlerList](https://osherove.com/blog/2004/12/31/manage-many-events-easily-with-eventhandlerlist.html)

- Dec 30, 2004

    ### [Next generation iteration: Array.ForEach and Delegate inference](https://osherove.com/blog/2004/12/30/next-generation-iteration-arrayforeach-and-delegate-inferenc.html)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
