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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:51:54+00:00 2026-06-16T13:51:54+00:00

Why does implicit operator have problems when I try to convert the return type

  • 0

Why does implicit operator have problems when I try to convert the return type to an object or a one custom type that I have defined myself?

I have no problem when I am trying to convert and return a simple type like an int, like this

public static implicit operator int(MyClass a)
        {
            return 123;
        }

However, when I try to convert the type into an object or a custom type, I will get an error. For example, I will get a compile-time error saying “User-defined conversion to System.Object” if I have something like this:

public static implicit operator object(MyClass a)
{
   return new {};
}

I will get the same kind of error if I have this:

public static implicit operator CustomTestObject(MyClass a)
{
   return new CustomTestObject();
}

How can I convert it to my own custom defined type for return when using an implicit operator?

  • 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-16T13:51:55+00:00Added an answer on June 16, 2026 at 1:51 pm

    You cannot declare an implicit conversion to one of your own base classes. System.Object is always your (direct or indirect) base class. Through inheritance there’s already an implicit conversion to the base class. So how could there be two implicit conversions? The C# spec has a good reson to disallow this!

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

Sidebar

Related Questions

I have a custom type that I created, which should be persisted in a
I have a generic class that I'm trying to implement implicit type casting for.
I have a custom user type that is used to map from a decimal
Does anyone know why UsernameExists wont return True. I must have my syntax messed
What I'm trying to do is create a new custom data type that behaves
To box a value type you cast it to System.Object - that in itself
I created a custom string object, but it does not modelbind when I post
Why does C# allow for the implicit conversion of an object to an int
I have an object of a certain type ( SpecialImage ) which implements an
I am trying to have a class that allows implicit casting to certain built

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.