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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:26:59+00:00 2026-05-31T13:26:59+00:00

I have a function which accepts two base class parameters. Within this function I

  • 0

I have a function which accepts two base class parameters. Within this function I wish to test the types of these parameters over a number of derived classes and then call a polymorphic function. See below to see my first attempt which won’t compile.

    public static double Intersect(baseClass s0, baseClass s1)
    {
          if (s1 is derivedClassB) return (s0 as derivedClassA).PolyMethod((derivedClassB)s1);

          else if (s1 is derivedClassC) return (s0 as  derivedClassA).PolyMethod((derivedClassC)s1);
                    else return 0.0;

    }

I thought i could use something like

Type dType = s0.GetType();
(s0 as dType).PolyMethod(derivedClassB) s1);

but this doesn’t work either.

  • 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-31T13:26:59+00:00Added an answer on May 31, 2026 at 1:26 pm

    Define your base class like this

    public abstract BaseClass
    {
        public abstract double PolyMethod(BaseClass s);
    }
    

    Define derived classes like this

    public DerviedClassX : BaseClass
    {
        public override double PolyMethod(BaseClass s)
        {
            return 0.0; // Return something usefull here.
        }
    }
    

    Then your method can be simplified like this

    public static double Intersect(BaseClass s0, BaseClass s1)
    {
        return s0.PolyMethod(s1);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a function in PostgreSQL which accepts two parameters viz varchar and
i have function, which has to accept two types of data - Observable collection
I have custom function which return a table it accepts two varchars, it splits
Hi guys I have a function which accepts this as a parameter - '
I have a function which accepts a string parameter such as: var1=val1 var2=val2 var3='a
I have a function which accepts fromRange and ToRange of an Excel cell. basically
I have a function which returns a one-sided intersection of values between two input
I have a function which calculates distance from database records. This function is called
I have a filter function which is supposed to check two fields in an
Let's say I have two classes that look like this: public class ByteFilter {

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.