Dart (Exercise)

2024-09-02
156
 

dart exercises.

dart: 1

Q. 1 1443
What does "?" mean in the variable statement in dart?
E.g.
String? name;
Answer

Nullable type

Explanation
"?" mean the value of this variable can be "null".

In Dart, by default, the variable can not be "null".

When you specify a type for a variable, parameter, or another relevant component, you can control whether the type allows null. To enable nullability, you add a ? to the end of the type declaration.

String? name //Nullable type. Can be `null` or string.

String name // Non-nullable type. Cannot be `null` but can be string.

You must initialize variables before using them. Nullable variables default to null, so they are initialized by default. Dart doesn't set initial values to non-nullable types.

dart dart variables Edit







E-Mail:[email protected]

www.yhlearn.com

2010 - 2024

打字練習

Admin 管理 Google Bing