Post

Code Monkey
Code Monkey@UnityCodeMonkey·
Is this valid code? Color? myColor = null; A) Yes B) No, myColor is a struct and cannot be null (answer in reply below)
English
2
0
11
5.2K
Code Monkey
Code Monkey@UnityCodeMonkey·
#### ANSWER #### #### ANSWER #### #### ANSWER #### #### ANSWER #### #### ANSWER #### #### ANSWER #### #### ANSWER #### #### ANSWER #### #### ANSWER #### #### ANSWER #### #### ANSWER #### #### ANSWER #### (A) Structs indeed cannot be null however in this example code myColor is not a Struct but rather a Nullable. Note the Question mark ? after the type, that marks the type as Nullable. When you make something Nullable you can make that type null, regardless of what that type is. This is all valid code: Color? myColor = null; int? myInt = null; bool? myBool = null; I have a lecture on Nullables in my C# Course youtube.com/watch?v=qZpMX8…
YouTube video
YouTube
English
0
0
12
1.6K
Paylaş