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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:51:15+00:00 2026-05-14T15:51:15+00:00

The problem of single dispatch is mostly familiar to people engaged in coding with

  • 0

The problem of single dispatch is mostly familiar to people engaged in coding with statically typed languages like Java and C#. The basic idea is:

While the runtime polymorphism allows us to dispatch to the right method call according to the type (runtime type) of receiver, for example:

IAnimal mything = new Cat();
mything.chop();

The method call will be performed according to the runtime type of mything, namely Cat.
This is the single dispatch capability (which is present in Java/C#).

Now, if you need to dispatch not only on the runtime type of receiver, but on the types of (multiple) arguments either, you face a little problem:

public class MyAcceptor {  
    public void accept (IVisitor vst) {...}   
    public void accept (EnhancedConcreteVisitor vst) {...}  
}

The second method never gets called, because in our ‘consumer’ code we just tend to treat different types of objects (visitors in my example) by their common supertype or interface.

That’s why I ask – because dynamic typing allows the multiple dispatch polymorphism and C# 4.0 has that dynamic keyword 😉

  • 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-14T15:51:16+00:00Added an answer on May 14, 2026 at 3:51 pm

    Yes, dynamic typing allows multiple dispatch – and no, you don’t have to create your own dynamic object to do it.

    Suppose we wanted to implement Enumerable.Count() ourselves, and we didn’t want a load of “if (source is IList)” tests in our code. We could write it like this:

    public static class Enumerable
    {
        public static int Count<T>(this IEnumerable<T> source)
        {
            dynamic d = source;
            return CountImpl(d);
        }
    
        private static int CountImpl<T>(ICollection<T> collection)
        {
            return collection.Count;
        }
    
        private static int CountImpl(ICollection collection)
        {
            return collection.Count;
        }
    
        private static int CountImpl<T>(string text)
        {
            return text.Length;
        }
    
        private static int CountImpl<T>(IEnumerable<T> source)
        {
            // Fallback
            int count = 0;
            foreach (T t in source)
            {
                count++;
            }
            return count;
        }
    }
    

    I’m not saying it would be a good idea, but that’s how it would work 🙂

    Note that you need to be careful not to introduce situations where you could end up with an ambiguous call for some types. This wouldn’t be an issue using classes for parameters, but consider that a single class can implement multiple interfaces.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not really sure if there is a single problem here or I have
I'm using Delphi 2010 on Windows 7 and have a problem with single quotes
currently i am relying on a proxy script to handle this problem of Single
I have a problem how do i replace a single dash(-) with a single
I have a strange problem that is only happening in a single location. I
I think I read every single web page relating to this problem but I
Problem: I have a table that prints out vertical but I would like it
I'm having a problem echoing a single line from a sql query. I'm still
Ok, so I've no problem getting a single image from a database. I use
Having a problem with single quote/apostophes in some php I am writing to parse

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.