What is the default boolean value in C#?

前端 未结 6 934
心在旅途
心在旅途 2020-12-05 09:17

A boolean (bool) can\'t be null. And:

bool foo; if(foo){} // Use of unassigned local variable \'foo\'

Why the default value is

6条回答
  •  囚心锁ツ
    2020-12-05 09:46

    The default value for bool is false. See this table for a great reference on default values. The only reason it would not be false when you check it is if you initialize/set it to true.

提交回复
热议问题