Aug 7, 2024
Invalid Cast Exception:
InvalidCastException
).Avoiding Exception-Throwing Methods:
as
keyword:
Handling Critical Paths:
try-catch
blocks to handle exceptions.Equality Comparison:
==
) and Equals
method do not always behave the same way:
Strings as Reference Types:
==
and Equals
return true for equal string values, even though they are different instances.Custom Objects:
Equals
is overridden.Best Practices:
Equals
to compare object values.GetHashCode
to ensure consistent behavior in collections (e.g., HashSet, Dictionary).Creating Unique Identifiers:
operator
keyword for custom equality checks.==
and !=
for symmetry.Understanding VAR:
var
is for implicit typing; the compiler infers the type at compile time based on the assigned value.Dynamic Keyword:
dynamic
exists in C# but is not supported in Unity for all builds.Use of VAR for Dictionary Types:
var
at a field level; must use explicit types instead.Explicit Type Definition: