Note that there are some explanatory texts on larger screens.

plurals
  1. POIndexer in Generic Array
    primarykey
    data
    text
    <p>Hi i have created a Generic Array that works fine for Int,String, Float or even my Own type named Customers. </p> <p>Generic Array has functions Add(), Sort(), ShowAll() thats working fine for Int, String, and even Customer Type except when i try to showAll() method for CustomerType that shows all the values that i have added through ADD() method.</p> <p>output is something like <code>GenericArray.Customer</code> </p> <p>not the values where as i wanted to have the values .</p> <p>i have solved it through </p> <p><strong><code>public class GArray&lt;T&gt; where T : Customer</code></strong></p> <p>but now i cant create Generic Array of type Int,Float . </p> <p>here is the ADD and ShowAll method of Class</p> <pre><code>public void Add(T temp) { if (index &gt;= values.Length) { T[] tempArray = new T[values.Length + 1]; Array.Copy(values, tempArray, values.Length); values = tempArray; } values[index] = temp; index++; } public void ShowAll() { for (int i = 0; i &lt; values.Length; i++) { Console.WriteLine(values[i]); } } </code></pre> <p>the values m adding</p> <pre><code> static void Main(string[] args) { GArray&lt;Customer&gt; customers = new GArray&lt;Customer&gt;(3); customers.Add(new Customer(101, "xyz")); customers.Add(new Customer(59, "abc")); customers.ShowAll(); } </code></pre> <p>i have talked with my frnd and he said that i have to create indexer my self . can some one help me how can i create indexer in this case that works fine for customerType or any Type. </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.
 

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