0

A nullable variable such as:

int? kitten;

has a type of kitten.Nullable`1

What does the 1 represent?

For context only, the reason for asking this question was my musings over:

If I have this value in a string (no access to the actual object/type/reference), and I want to determine if it is nullable or not, would checking .endsWith(".Nullable`1") be consistently OK or would the number change depending on some unforseen factor?

NibblyPig
  • 51,118
  • 72
  • 200
  • 356
  • 2
    The number won't change because it's the number of generic arguments to the underlying `Nullable` type, and that's always 1. As for your main question... – Frédéric Hamidi Sep 30 '15 at 09:31
  • Also this question would most probably have been better as 2 questions (as they are are not completely related to each other and could easily / probably better be answreed separately. – Thomas Sep 30 '15 at 09:35
  • @OP also: From what I read from our question it COULD be that it is similar but sufficiently different form the other question to not really be a duplicate of it (as that one asks for objects nullable but YOU seem to ask if a value in a string is nullable?). maybe if you could elaborate that more then it could be that your question is different enough (at least if the other question didn't already answer you) – Thomas Sep 30 '15 at 09:39
  • 2
    I wasn't asking how to check if a type is nullable, I was just adding some context. Also this was specifically if you have the type as a string, not if you have access to the type object (asp.net mvc model validation will give you the parameter type as a string, not as a type). Thanks for the specific answer Frederic. I have clarified in the question for googlers. This is *not* a duplicate. – NibblyPig Sep 30 '15 at 14:55
  • NOW it's a duplicate! Incredibly hard to google/search questions like what does `1 mean :-) – NibblyPig Oct 01 '15 at 07:56

0 Answers0