using nullable types


Tony Johansson


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\ConsoleApplication1\ConsoleApplication1\Program.cs 12 26

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.



Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

nullable types 1
private and internal 5
simple example 14
why do I get compile error 2
nullable types 2
generics problem 2
using nullable types in generics 3
more about nullable types where the Value property is used 2