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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:28:55+00:00 2026-05-26T21:28:55+00:00

Given these types: class A { } class B { public static implicit operator

  • 0

Given these types:

class A { }
class B
{
    public static implicit operator A(B me)
    {
        return new A();
    }
}

class Test<T> where T : A { }

I tried

var b = new Test<B>();

And expected it to fail, which it did. But the error message is

The type ‘B’ cannot be used as type parameter ‘T’ in the generic type or method ‘Test’. There is no implicit reference conversion from ‘B’ to ‘A’.

But there is an implicit reference conversion from B to A. Is this just a strange message? There is not an implicit reference conversion as Adam Robinson’s answer shows. The message is correct.

Note that MSDN says:

where T : (base class name) – The type argument must be or derive from the specified base class.

Which explains why it is not allowed since B does not derive from A

  • 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-26T21:28:56+00:00Added an answer on May 26, 2026 at 9:28 pm

    No, what you’re trying to do is not possible. An implicit reference conversion is not the same thing as an implicit type conversion. Your code defines an implicit type conversion, which is where you could do the following:

    B foo = new B();
    A bar = foo;
    

    Note, however, that foo and bar now contain different references. The implicit type conversion creates a new instance of A that should be (by convention) logically equivalent to foo. But the point is that it’s a different reference.

    A reference conversion would be where the reference itself does not change, which means that the type in question must either inherit from (for classes) or implement (for interfaces) the type in question. If I do this:

    class A { }
    class B : A { }
    

    Then my code above will now hold the same reference in foo and bar. This is what is meant by an implicit reference conversion. Conversely, an explicit reference conversion would be downcasting, like this:

    A foo = new B();
    B bar = (B)foo;
    

    Again, the references are the same, but the cast was explicit.

    So, in short, the MSDN documentation is clearer but less precise.

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

Sidebar

Related Questions

Given this class with an implicit cast operator: public class MyDateTime { public static
This is easier to explain with an example. Given these two classes: public class
hy there! given is this class: public static class FooClass<TFoo> { public static TFoo
Given the Java code below, what's the closest you could represent these two static
Given the following two interfaces (these are small examples, not my actual implementation): public
How do I make code like this thread safe? public static class Converter {
Given a generic class definition like public class ConstrainedNumber<T> : IEquatable<ConstrainedNumber<T>>, IEquatable<T>, IComparable<ConstrainedNumber<T>>, IComparable<T>,
public class Anagram { public static void main(String[] args) { String a = Despera
Given these two queries: Select t1.id, t2.companyName from table1 t1 INNER JOIN table2 t2
Given these tables: create table Orders ( Id INT IDENTITY NOT NULL, primary key

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.