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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:23:49+00:00 2026-06-05T01:23:49+00:00

public class Derived : BaseClass { public Derived(string name) : base(name) {} public static

  • 0
public class Derived : BaseClass
{
    public Derived(string name) : base(name) {}

    public static implicit operator BaseClass(Derived derived)
    {
        return new BaseClass(derived.ColorHex);
    }

    public static implicit operator Derived(BaseClass baseclass)
    {
        return new Derived(baseclass.name);
    }
}

This won’t work. why isn’t it allowed?
I can potentially write the logic necessary for it to make sense, especially when converting from the base to the derived one.

EDIT:Changed the title of the question

  • 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-05T01:23:52+00:00Added an answer on June 5, 2026 at 1:23 am

    Because there is already an implicit conversion from Derived to BaseClass, and the converse does not make any sense.

    Regarding the latter: if your Base objects are meant to be implicitly convertible to Derived — why aren’t they Derived objects in the first place?

    Obligatory quotes from the standard:

    6.1.6 Implicit reference conversions

    The implicit reference conversions are:

    • […]
    • From any class-type S to any class-type T, provided S is
      derived from T.

    This says there’s an implicit conversion Derived => Base, as we all know.

    6.2.4 Explicit reference conversions

    The explicit reference conversions are:

    • […]
    • From any class-type S to any class-type T, provided S is a base class of T.
    • […]

    This says there’s already an explicit conversion Base => Derived (which is what allows you to try downcasting at runtime).

    6.4.1 Permitted user-defined conversions

    C# permits only certain user-defined conversions to be declared. In
    particular, it is not possible to redefine an already existing
    implicit or explicit conversion.

    And this says that since the two conversions of interest are already defined by the language, you can’t redefine them.

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

Sidebar

Related Questions

public class Test{ public void Test(String name){}; public static void main() { Test t=new
With code like the following public class Task { string Name; public static bool
public class ProtectedClass { private String name; public static void changeName(ProtectedClass pc, String newName)
Given this code: class base { public: string foo() const; // Want this to
I have a base class that has a virtual property: public virtual string Name
I'm probably doing this totally wrong.. public class BaseClass { public string result {
Given public class Original { public static DoStuff() { } } public class Derived
In a WebView-derived class I override loadUrl(): @Override public void loadUrl(String url) { super.loadUrl(url);
public class DBAdapter { public static final String COLUMN_ID = ID; public static final
In a derived class If I redefine/overload a function name from a Base class,

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.