Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4619002
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:21:55+00:00 2026-05-22T02:21:55+00:00

Hi i have created a Generic Array that works fine for Int,String, Float or

  • 0

Hi
i have created a Generic Array that works fine for Int,String, Float or even my Own type named Customers.

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.

output is something like
GenericArray.Customer

not the values where as i wanted to have the values .

i have solved it through

public class GArray<T> where T : Customer

but now i cant create Generic Array of type Int,Float .

here is the ADD and ShowAll method of Class

public void Add(T temp)
        {

            if (index >= 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 < values.Length; i++)
        {
            Console.WriteLine(values[i]);                
        }
    }

the values m adding

 static void Main(string[] args)
        {                        
            GArray<Customer> customers = new GArray<Customer>(3);
            customers.Add(new Customer(101, "xyz"));
            customers.Add(new Customer(59, "abc"));

            customers.ShowAll();
            }

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:21:56+00:00Added an answer on May 22, 2026 at 2:21 am

    I think,If I understand the question (output is something like GenericArray.Customer, not the values where as i wanted to have the values) you should add in Customer definition:

    public override string ToString()
    {
        // return something you want to show to identify your customer
        // e.g. return Name;  
        return ...           
    }
    

    I explain: when you use Console.WriteLine(values[i]) you tell C# to write to console Customer object… and it writes out then name of the class, as it’s the default behaviour.
    Defining in Customer class the default string to be converted to makes what you please…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created the type IntPtr<T> to act like a generic pointer that c/c++ have:
I have created a PHP-script to update a web server that is live inside
I have created a UserControl that has a ListView in it. The ListView is
I have created a few small flash widgets that stream .mp3 audio from an
i have created a workflow activity that do give the item creater of a
I have the need to store a list/collection/array of dynamically created objects of a
I have a Read generic function that does its job very well. It reads
I have a class that contains the following two properties: public int Id {
I have a class that creates a static array of all properties, using a
I have created a custom generic queue which implements a generic IQueue interface, which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.