I have a node class. Variables of this type may be null, the node class contains a pointer variable to another node. If the node class is null, how do I change the getter to return null when attempting to access the pointer to the next node? My code:
public class Node
{
private T _data;
private Node _next;
public T Data
{
get => _data;
set
{
if (this != null)
{
_data = value;
}
}
}
public Node Next
{
get
{
if (this != null)
{
return _next;
}
return null;
}
set
{
if (this != null)
{
_next = value;
}
}
}
public Node(T data)
{
Data = data;
Next = null;
}
}
I tried adding a null check to the getter for the Next property, but it doesn't appear to be working.error message