Section 2: Code Fixing

11. Fix this method declaration:

public void PrintMessage {
    Console.WriteLine("Hello!");
}
chevron-rightAnswerhashtag
public void PrintMessage() {
    Console.WriteLine("Hello!");
}

Added parenthesis after method name.


12. Fix this struct constructor issue:

struct Player {
    public string Name;
    public Player() {
        Name = "Default";
    }
}
chevron-rightAnswerhashtag
struct Player {
    public string Name;
    public Player(string name) {
        Name = name;
    }
}

Structs cannot have parameterless constructors.


13. Fix this enum:

chevron-rightAnswerhashtag

Enum values must be integers, not strings.


14. Fix this property declaration:

chevron-rightAnswerhashtag

Added private set; to allow assignment inside the constructor.


15. Fix this delegate declaration:

chevron-rightAnswerhashtag

Corrected delegate syntax.


16. Fix this incorrect loop:

chevron-rightAnswerhashtag

Added missing semicolon.


17. Fix this incorrect try-catch block:

chevron-rightAnswerhashtag

Explicitly throwing and catching Exception.


18. Fix this static class issue:

chevron-rightAnswerhashtag

Static classes cannot have instance variables.


19. Fix this incorrect property setter:

chevron-rightAnswerhashtag

Removed incorrect set keyword in constructor.


20. Fix this incorrect event handling in Unity:

chevron-rightAnswerhashtag

Used null-conditional operator to prevent null reference exceptions.

Last updated