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; }  
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,119 questions
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 56,026 Reputation points
    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 40,816 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