Questions
heshaniheshaniasked 4 months ago
C# code throw a NullReferenceException error, how do I fix?
1

1 Answers

Accepted
codegenlabcodegenlabanswered 4 months ago
1. use if  statement to checks whether the value object is null or not,
If (value == null)
{
 // code here
}
2. use Null Conditional Operator(),
public static void Authentication(User user)
{
 Console.WriteLine(user?.Name);
 // use ?. operator to check Name is not null.
}
1