Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C# What does the "?" symbol do when it's placed after a generic parameter

I've come across this code:
C#
public static Task<long?> GetPageLength() 
{
   // Code 
   ...
}


What I have tried:

Googling but didn't find any information.
Posted
Updated 14-Apr-18 2:29am

1 solution

The question mark indicates it's not a long any more, but a nullable long.
As you know, long variables are value types, and value types cannot contain null - so you can use the question mark to create a special version of a value type that can also contain null: Nullable Types (C# Programming Guide) | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900