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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:29:29+00:00 2026-06-18T11:29:29+00:00

From C# 4.0 Spec section 6.1.6: The implicit reference conversions are: […] From any

  • 0

From C# 4.0 Spec section 6.1.6:

The implicit reference conversions are:

[…]

From any reference-type to an interface or delegate type T if it has
an implicit identity or reference conversion to an interface or
delegate type T0 and T0 is varience-convertible (13.1.3.2) to T.

Vladimir Reshetnikov tells us that there is an implicit reference conversion from List<string> to IEnumerable<object>. But, how can I apply this to a user defined type (is it even possible)?

I tried an implicit operator, custom derived types and a few varitions there-of…but I cannot reproduce the scenerio. I have:

class Program
{
    static void Main(string[] args)
    {
        IEnumerable<object> specialClassConversion = new List<string>();
        IEnumerable<A> userdefinedTypeConversion = new List<B>();
        A implicitConversion = new B();//varience-convertible
        IC<A> explicitConversion = (IC<A>)new D<B>();//OK, varience-convertible
        IC<A> implicitConversion2 = new D<B>();//does not compile
    }
}

class A { }

class B : A { }

interface IC<T> { }    

class D<T> 
{
    //public static implicit operator IC(D<T> m)//Error: user-defined conversions to or from an interface are not allowed
    //{
    //    return null;
    //}
}
  • 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-18T11:29:30+00:00Added an answer on June 18, 2026 at 11:29 am

    If you want a user-defined class or struct to be implicitly convertible to an interface, let your class/struct implement that interface.

    (Edit)

    And if you want IC<B> to be implicitly convertible to IC<A>, make the IC<T> interface covariant in T by specifying the out keyword, interface IC<out T> { }. The quote from the spec you gave tells that the “composition” of these two implicit conversion is also an implicit conversion.

    Source:

    interface IC<out T> {  }
    
    class D<T> : IC<T>  { }
    

    (End edit)

    Regarding the List<string> class, it implements IEnumerable<string> which in turn is convertible (implicitly) to IEnumerable<object> because IEnumerable<out T> is covariant (out) in T.

    (One reason why they didn’t allow you to make a public static implicit operator which converts to/from the interface, is that somone could write a derived class which inherited from your class and implemented the interface. That would give a “natural” conversion between their class and the interface, but the public static implicit operator would also apply, leading to two conversions (one “natural” and one “user-defined”) between the types, which would be confusing and ambiguous.)

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

Sidebar

Related Questions

Scala 2.8 spec says in section 7.3 (highlighting is mine): Implicit parameters and methods
Hi i have a spec for fetch the files from server and predict the
I am trying to use the tranlsation webservice from MyMemory: http://mymemory.translated.net/doc/spec.php Unfortunately, Zend_Soap_Client does
This is from Michael Hartl's book, section 8.4. RSpec is testing a successful signup
I added the following Pre section to my rpm installer's build.spec. When I install
Here is a extract from the grammar section of the C# Language Specification: Is
With Rspec 2 the rspeccommand is supposed to run the tests, replacing spec from
Servus Ninjas, this is what ecmascript 5 spec. (page 118) in the section Function.prototype.apply(thisArg,
How can I sign and encrypt my WCF clients service call (from spec: All
From my website, I have a button which calls a method and then generates

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.