Skip to content

Why the code give me an error

Abdelbasset Barkat

Asked Apr 13, 2014, 1:38 PM EDT3 answers
Share
LinkedInX
Hi there 
I have this code 
public class NodeList<T> : Collection<Node<T>>
{
public NodeList() : base() { }
public NodeList(int initialSize)
{ // Add the specified number of items
for (int i = 0; i < initialSize; i++)
base.Items.Add(default(Node<T>));
}
public Node<T> FindByValue(T value)
{ // search the list for the value
foreach (Node<T> node in Items)
if (node.Value.Equals(value)) return node;
// if we reached here, we didn't find a matching node
return null;
}
}
source : http://msdn.microsoft.com/en-US/library/ms379572(v=vs.80).aspx
i
n visual studio 2010 c# language it gives me an error in
public class NodeList<T> : Collection<Node<T>>
so I change it to ICollection
and then the error jump to base.items , exactly with items
so what is wrong ... it is from msdn.microsoft

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    The base keyword is used to use the code from the parent class in case of inheritance...

    You will need to define the Public class Node<> for this..

    You just missed this code from the MSDN link..

    PowerShell
    public class Node<T> {         // Private member-variables         private T data;         private NodeList<T> neighbors = null;          public Node() {}         public Node(T data) : this(data, null) {}         public Node(T data, NodeList<T> neighbors)         {             this.data = data;             this.neighbors = neighbors;         }          public T Value         {             get             {                 return data;             }             set             {                 data = value;             }         }          protected NodeList<T> Neighbors         {             get             {                 return neighbors;             }             set             {                 neighbors = value;             }         }     } }
    0
  • 0
    Thnks I did that but still the same errot
    0
  • 0
    put the complete error here...
    0