Single line if null or int return

c#, dbnull, if-statement, integer, nullable

Solution

Explicitly cast to `int?` like:

n = (reader[0] == null)? null :(int?) Convert.ToInt32(reader[0]);

Or:

n = (reader[0] == null) ? (int?) null : Convert.ToInt32(reader[0]);

Problem

I'm trying single line if statement as follow and I'm getting error justifiably.How should i do it? ``` int? n; n = (reader[0] == null)? null : Convert.ToInt32(reader[0]); ```

Original source