English

Error: Cannot implicitly convert type '[type]?' to '[type]'

Error Message

Programming in C# within Visual Studio 2005 (.NET 2.0) can lead to the following error message:

"Cannot implicitly convert type '[type]?' to '[type]'. An explicit conversation exists (are you missing a cast?)"

Cause

In the .NET Framework 2.0, C# nullable data types are denoted with a question mark. 'int' must be set, but 'int?' may be null.

Solution or Workaround

For nullable data types, add a question mark to the end when declaring it.

For example, to declare a nullable integer named test:

Code:
int test;

should be:

Code:
int? test;