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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:13:28+00:00 2026-06-03T13:13:28+00:00

When we have two structs, and one is implicitly convertible to the other, then

  • 0

When we have two structs, and one is implicitly convertible to the other, then it seems like the System.Nullable<> versions of the two are also implicitly convertible. Like, if struct A has an implicit conversion to struct B, then A? converts to B? as well.

Here is an example:

struct MyNumber
{
  public readonly int Inner;

  public MyNumber(int i)
  {
    Inner = i;
  }

  public static implicit operator int(MyNumber n)
  {
    return n.Inner;
  }
}

Inside some method:

MyNumber? nmn = new MyNumber(42);
int? covariantMagic = nmn; // works!

In the C# Language Specification Version 4.0 we read that a conversion like this shall exist for “the predefined implicit identity and numeric conversions”.

But is it safe to assume that it will also work for user-defined implicit conversions?

(This question might be related to this bug: http://connect.microsoft.com/VisualStudio/feedback/details/642227/)

  • 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-03T13:13:30+00:00Added an answer on June 3, 2026 at 1:13 pm

    But is it safe to assume that it will also work for user-defined implicit conversions?

    Yes. From section 6.4.2 of the C# 4 spec:

    Given a user-defined conversion operator that convers from a non-nullable value type S to a non-nullable value type T, a lifted conversion operator exists that converts from S? to T?. This lifted conversion operator performs an unwrapping from S? to S followed by the user-defined conversion from S to T, followed by a wrapping from T to T?, except that a null-valued S? converts directly to a null-valued T?.

    A lifted conversion operator has the same implicit or explicit classification as its underlying user-defined conversion operator. The term "user-defined conversion" applies to the use of both user-defined and lifted conversion operators.

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

Sidebar

Related Questions

I have three structs, one of which inherits from the other two: typedef struct
I have two structs like so: public struct KeyLog { Keys key; DateTime time;
I have two window form applications written in C, one holds a struct consisting
So, I have two structs: struct coordinate { float x; float y; } struct
I have two DropDownListBoxes one is called ddlDay and the other is ddlMonth. As
I have two structs (part of the assignment). A list of one -- Activity,
Summary Let's say I have two C# 4.0 classes, one inheriting from the other:
I have an array of structs. The struct has two function pointers. Each element
I have two structs containing some fields: struct MyNodeData, and struct MyEdgeData. When I
I have two structs: // ----- non-const ----- struct arg_adapter { EArgType type; //

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.