Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Simply no. As this is not possible to access a method from a null object. In your case you want say</p> <pre><code>F f = new F() // where f = null f.SomeMethod(); // ?????? not possible </code></pre> <p>In this case you get a Null Reference Exception. You can see Darin's Comment and Explanation too on the same. How could you access anything from null, which means nothing. I have no idea about legacy but .Net does not provides you such things. Instead you can set it to null when its not needed anymore.</p> <p>Ex From MSDN</p> <pre><code>public class Node&lt;T&gt; { // Private member-variables private T data; private NodeList&lt;T&gt; neighbors = null; public Node() {} public Node(T data) : this(data, null) {} public Node(T data, NodeList&lt;T&gt; neighbors) { this.data = data; this.neighbors = neighbors; } public T Value { get { return data; } set { data = value; } } protected NodeList&lt;T&gt; Neighbors { get { return neighbors; } set { neighbors = value; } } } } public class NodeList&lt;T&gt; : Collection&lt;Node&lt;T&gt;&gt; { public NodeList() : base() { } public NodeList(int initialSize) { // Add the specified number of items for (int i = 0; i &lt; initialSize; i++) base.Items.Add(default(Node&lt;T&gt;)); } public Node&lt;T&gt; FindByValue(T value) { // search the list for the value foreach (Node&lt;T&gt; node in Items) if (node.Value.Equals(value)) return node; // if we reached here, we didn't find a matching node return null; } } and Right—that operate on the base class's Neighbors property. public class BinaryTreeNode&lt;T&gt; : Node&lt;T&gt; { public BinaryTreeNode() : base() {} public BinaryTreeNode(T data) : base(data, null) {} public BinaryTreeNode(T data, BinaryTreeNode&lt;T&gt; left, BinaryTreeNode&lt;T&gt; right) { base.Value = data; NodeList&lt;T&gt; children = new NodeList&lt;T&gt;(2); children[0] = left; children[1] = right; base.Neighbors = children; } public BinaryTreeNode&lt;T&gt; Left { get { if (base.Neighbors == null) return null; else return (BinaryTreeNode&lt;T&gt;) base.Neighbors[0]; } set { if (base.Neighbors == null) base.Neighbors = new NodeList&lt;T&gt;(2); base.Neighbors[0] = value; } } public BinaryTreeNode&lt;T&gt; Right { get { if (base.Neighbors == null) return null; else return (BinaryTreeNode&lt;T&gt;) base.Neighbors[1]; } set { if (base.Neighbors == null) base.Neighbors = new NodeList&lt;T&gt;(2); base.Neighbors[1] = value; } } } public class BinaryTree&lt;T&gt; { private BinaryTreeNode&lt;T&gt; root; public BinaryTree() { root = null; } public virtual void Clear() { root = null; } public BinaryTreeNode&lt;T&gt; Root { get { return root; } set { root = value; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload