0

i´ve found a code in c# with the following variable declaration in a class

public class Foo
{
    public int ID { get; set; }
    public int Age { get; set; }
    public string name{ ger; set;}
    public bool? Status { get; set; }
}

What does the '?' means, i've just found answer for operator '??' and '?' is null, but not for variable daclaration

Tetsuya Yamamoto
  • 24,297
  • 8
  • 39
  • 61
Mateus Martins
  • 442
  • 3
  • 16

1 Answers1

4

It makes the type Nullable, where it usually would not be.

https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/nullable-types/

Robin Bennett
  • 3,192
  • 1
  • 8
  • 18
  • Out of interest, why is this downvoted? It's the correct answer. If a question is a duplicate, then it should be closed as such; that ought not to influence answer voting? – Bathsheba Feb 06 '19 at 16:16
  • @Bathsheba The only reason I can think is that it's not useful (which is one of the possible *"official"* reasons for DVing), as the answer adds nothing that isn't in the dupe – Nick is tired Feb 06 '19 at 16:17
  • i don´t know, i just not found what i'm asking here, there is no necessity to downvote, just close, and stop, this looks like hating – Mateus Martins Feb 06 '19 at 16:18
  • @NickA: Hum. I always read "Not useful" as being "Not useful w.r.t. the question", rather than some kind of "globally" not useful. – Bathsheba Feb 06 '19 at 16:18
  • 5
    @MateusMartins: Downvoting should never be taken (or given) personally. – Bathsheba Feb 06 '19 at 16:18
  • @Bathsheba I dunno honestly, it's the only reason I can think of (except for the more obvious, *"answering an obvious dupe"* reason, but I think that's generally saved for high rep users who *should* know better) – Nick is tired Feb 06 '19 at 16:19
  • @NickA: Well I don't lurk around on the C# tag too much, and different tags do seem to have different cultures. I think the correct course of action here is to upvote the answer (to indicate correctness), then close and delete the question. – Bathsheba Feb 06 '19 at 16:20
  • @Bathsheba i know, but that is no necessity of downvote, i did´nt found an answer, and isn´t that hard to mark as duplicated, that is no necessity to downvote mine question, and other people answers – Mateus Martins Feb 06 '19 at 16:23
  • @Bathsheba and now in blocked from asking for 2 days, only by the downvoting – Mateus Martins Feb 06 '19 at 16:32
  • 2
    Possible reason for downvoting the question would be lack of research effort, because using search terms from the question in google (like [`"bool? c#"`](https://www.google.com/search?q=bool%3F+c%23)) returns several links that describe the meaning. Downvotes for the answer could only be for it's brevity, I guess? Some people just like to downvote, I think. Personally, I like this answer because it's brief, direct, and gives a link for more info (although sometimes links die, so it's often better to highlight the relevant "more info" bits in the answer itself). – Rufus L Feb 06 '19 at 16:56