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 6172653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:25:53+00:00 2026-05-23T23:25:53+00:00

I created an object array with different types of elements in them: public static

  • 0

I created an object array with different types of elements in them:

public static int a;
public static string b;
public static ushort c;

object[] myobj = new obj[]{ a, b, c};

If I want to create an array that contains elements of arrays of this myobj type, how would I do it?

I mean something like this:

myobj[] myarray = new myobj[];  <= but to do this, myobj should be a type. 

Not sure how to work it out.

Thanks everyone.

  • 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-23T23:25:54+00:00Added an answer on May 23, 2026 at 11:25 pm

    How about we use a Dictionary to store any types you need?

    So, while you will not exactly have myType.a, you can have myType.Values["a"], which is close enough, makes use of standard C# constructs, and gives you lots of flexibility/maintainability

    public class MyType
    {
        public MyType()
        {
            this.Values = new Dictionary<object, object>();
        }
    
        public Dictionary<object, object> Values
        {
            get;
            set;
        }
    }
    

    And sample usage:

    using System;
    using System.Collections.Generic;
    
    public static class Program
    {
        [STAThread]
        private static void Main()
        {
            var myTypes = new MyType[3];
    
            myTypes[0] = new MyType();
            myTypes[1] = new MyType();
            myTypes[2] = new MyType();
    
            for (var current = 0; current < myTypes.Length; ++current)
            {
                // here you customize what goes where
                myTypes[current].Values.Add("a", current);
                myTypes[current].Values.Add("b", "myBvalue");
                myTypes[current].Values.Add("c", (ushort)current);
            }
    
            foreach (var current in myTypes)
            {
                Console.WriteLine(
                   string.Format("A={0}, B={1}, C={2}", 
                                  current.Values["a"], 
                                  current.Values["b"],
                                  current.Values["c"]));
            }
    
     }
    

    Plus, if you want, you can easily add an indexer property to your class, so you can access elements with the syntax myType["a"]. Notice that you should add error checking when adding or retrieving values.

    public object this[object index]
    {
        get
        {
            return this.Values[index];
        }
    
        set
        {                    
            this.Values[index] = value;
        }
    }
    

    And here’s a sample using indexer. Increment the entries by ‘1’ so we see a difference in the ouptut:

    for (var current = 0; current < myTypes.Length; ++current)
    {
        myTypes[current]["a"] = current + 1;
        myTypes[current]["b"] = "myBvalue2";
        myTypes[current]["c"] = (ushort)(current + 1);
    }
    
    foreach (var current in myTypes)
    {
        Console.WriteLine(string.Format("A={0}, B={1}, C={2}", 
                                        current["a"], 
                                        current["b"], 
                                        current["c"]));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently turning an array of pixel values (originally created with a java.awt.image.PixelGrabber object)
I have a need to archive an array of objects of several different types.
When I use new[] to create an array of my classes: int count =
I'm trying to create a custom JSP tag that would take an array object
I'm reusing a created Object just to change a Date and the ordinal value,
I would like to return the id of a newly created object for my
Is it bad javascript practice to not assign a newly created object to a
I'm using a VBO with an interleaved array to render a obj (model format)
Is there a way to generically remove an object from an array? (maybe not
I'm using Silverlight 4 on IE 8. I have created a new Silverlight web

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.