using nullable types

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tony Johansson

    using nullable types

    Hello!

    This construction
    int? op1 = 5;
    int result = op1 * 2;

    gived a compile error with
    Error 1 Cannot implicitly convert type 'int?' to 'int'. An explicit
    conversion exists (are you missing a cast?)
    C:\tony\Console Application1\Co nsoleApplicatio n1\Program.cs 12 26
    ConsoleApplicat ion1

    If I instead have this construction
    int? op1 = 5;
    int result = op1 * 2 ?? 12;
    Then no compile error will occur.

    I mean that because I don't have a nullable type for result it should
    give a compile error as the first example did.

    //Tony



  • Jon Skeet [C# MVP]

    #2
    Re: using nullable types

    On Jun 30, 10:55 am, "Tony Johansson" <johansson.ande rs...@telia.com >
    wrote:

    <snip>
    I mean that because I don't have a nullable type for result it should
    give a compile error as the first example did.
    Please see my response to your other post.

    Jon

    Comment

    Working...