Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>I just want to know if i have missed or done something wrong?</p> </blockquote> <p>The design you're showing here is missing a few things. First, you said you want to create a <em>generic</em> list. How are you going to store generic data in an integer array?</p> <p>Also, the signature you give for <code>addItems</code> is</p> <pre><code>public void addItems() </code></pre> <p>and the signature you give for <code>removeItems</code> is</p> <pre><code>public void removeItems() </code></pre> <p>How does your list object know what to add, if it isn't given any data? Similarly, how does it know what to remove, if the client code doesn't tell it (you could always remove the first item, or always remove the last item, but then you're in stack or queue territory, not the standard object-oriented list API).</p> <p>I'd recommend looking at the API for <a href="http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx" rel="nofollow">System.Collections.Generic.List</a>, which is the built-in class you should be trying to emulate here. You don't need to implement all the properties and methods that List implements, but you should implement parts of that API. I would recommend</p> <pre><code>public sealed class MyList&lt;T&gt; { public int Count { get; } public T this[int index] { get; set; } public MyList(); public void Add(T item); public void RemoveAt(int index); } </code></pre> <p>as the bare minimum API for a list class. You'd implement it by declaring a field of type <code>T[]</code> as the backing store, plus an internal <code>size</code> field. Don't forget that, if client code adds more items than the length of the backing store, you have to allocate a new backing store array (probably double the size of the old one), copy the elements to the new array, and start treating the new array as the backing store.</p> <p>You should also look into implementing <a href="http://msdn.microsoft.com/en-us/library/9eekhta0.aspx" rel="nofollow">System.Collections.Generic.IEnumerable</a>, which isn't strictly necessary, but makes a collection class much more useful.</p>
    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. VO
      singulars
      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