What is null/nil in C# and how to work with it?
Hello everyone! I started learning C# and encountered the concept of null. In other languages I've seen nil or None, but in C# it seems to be the same thing. Could you explain what exactly null means in the context of reference types and how to properly work with it?
I tried writing simple code but get a NullReferenceException. Here's an example:
public class Person { public string Name { get; set; } }\n\nPerson person = null;\nConsole.WriteLine(person.Name); // Error: Object reference not set to an instance of an object.I expected person.Name to return an empty string or null without an exception. How can I avoid such errors? I tried checking with if (person != null), but it clutters the