Boolean is true by default ?

Marc Roussel 41 Reputation points
2022-10-10T12:45:04.983+00:00

I created a class with a Boolean. When I instantiate it, my Boolean is true. I don't understand. I thought the default for Boolean was false ! Any ideas ?

Right now, I'm forced to use this attribute :

[

DefaultValue(false)]  
public bool IsDelete { get; set; }  
Developer technologies | .NET | .NET Runtime
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2022-10-12T15:46:16.423+00:00

    you are looking at swagger's display of sample data. it always sets booleans to true, just as it it uses now for DateTime (which default to minimum)

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Olaf Helper 47,436 Reputation points
    2022-10-10T13:01:18.56+00:00

    See bool (C# reference): "The default value of the bool type is false"
    There must be code setting the property to True


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.