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

  • Home
  • SEARCH
  • 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 9193327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:08:06+00:00 2026-06-17T21:08:06+00:00

I have an explicit conversion setup between two reference types. class Car { public

  • 0

I have an explicit conversion setup between two reference types.

class Car
{
    public void Foo(Car car)
    {

    }

    public static explicit operator Bike(Car car)
    {
        return new Bike();
    }

}

class Bike
{

}

If I invoke Foo and pass a type of Bike, then I must perform an explicit conversion.

            Car myCar = new Car();
            Bike bike = (Bike)myCar;            
            myCar.Foo(bike);//Error: Cannot convert from Bike to Car.

However, if I add an extension method, then explicit conversio is no longer required.

        public static void Foo(this Car car, Bike bike)
        {
            car.Foo(bike);//Success...
        }

Why is the extension method able to invoke Foo with a type of Bike implicitly?

  • 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-17T21:08:08+00:00Added an answer on June 17, 2026 at 9:08 pm

    Now that you’ve modified the code to show;

    public static void Foo(this Car car, Bike bike)
    {
        car.Foo(bike);//Success...
    }
    

    All you’ve done is create an ironic StackOverflowException. This method is now just calling itself recursively, not the implementation of Foo in Car.

    TIP: Get yourself a copy of ReSharper – it’ll put a nice circle-arrow icon on this line of code to show you what’s going on without actually needing to compile or run it. 🙂

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

Sidebar

Related Questions

If I define an explicit conversion operator between two types, shouldn't it follow that
if I have two classes, and have defined an explicit type conversion between them,
I am creating an explicit conversion operator to convert between a generic list of
I have an array of class objects: class Foo { public $A; public $B;
What languages other than C and C++ have explicit reference and pointer type qualifiers?
I would like to have an explicit cast between from a string to an
suppose I have a class with many explicit (statically allocated) members and few pointers
I have the following code in my context, and no explicit table-class mapping, yet
I have a struct like this, with an explicit conversion to float: struct TwFix32
I have this code: public static IEnumerable<dcCustomer> searchCustomer(string Companyname) { TestdbDataContext db = new

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.