What is the default boolean value in C#?

前端 未结 6 926
心在旅途
心在旅途 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:47

    It can be treated as defensive programming approach from the compiler - the variables must be assigned before it can be used.

提交回复
热议问题