H
H
h1_0ne2019-01-23 02:08:59
C++ / C#
h1_0ne, 2019-01-23 02:08:59

How to convert types with a question mark to types without it?

How to convert type "long?" in "long"?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
#
#, 2019-01-23
@mindtester

https://docs.microsoft.com/en-us/dotnet/csharp/pro...

M
Mikhail, 2019-01-23
@makarychev13

long? is analog Nullable<T>. If you look at the documentation, it becomes clear that this is a structure with two public fields: HasValue and Value, so it works like this:

//вариант 1
long? foo = ...;
if (foo.HasValue) 
{
  bar(foo.Value);
}

//вариант 2 (для самых смелых)
bar(foo.Value);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question