Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Anyway to keep different value types in the same array?

Posted on 2013-12-02
4
254 Views
Last Modified: 2013-12-02
What I would like to know is - Is there a way I can do this in C#?:

array(
   array("Joe" = true),
   array("Bob" = 3),
   array("Alex" = "Hello")
)

Having stored different value types in the array like that.
0
Comment
Question by:vituxa
  • 2
  • 2
4 Comments
 
LVL 25

Expert Comment

by:SStory
ID: 39690284
You can store an array of objects. An object is the base "object" of all objects like strings or whatever. You can create and array of objects and put anything into it, but then you'd have to evaluate what those objects are to cast them first.
Of stuff your own objects inside it, each having a tostring overriden function so you could always get the string value.
0
 
LVL 1

Author Comment

by:vituxa
ID: 39690315
Any code sample would be greatly appreciated.
0
 
LVL 25

Accepted Solution

by:
SStory earned 500 total points
ID: 39690445
Here are some samples:
http://stackoverflow.com/questions/7329178/array-or-someother-collection-where-i-can-store-multiple-types

array1[0] = new object();
array1[1] = new StringBuilder("Initialized");
array1[2] = "String literal";
array1[3] = 3;
array1[4] = null;

Open in new window

(source: http://stackoverflow.com/questions/6482331/how-to-add-different-types-of-objects-in-a-single-array-in-c)
0
 
LVL 1

Author Closing Comment

by:vituxa
ID: 39690572
Thank you! That was exactly what I needed.
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.NET 2008 Winforms Signing 13 31
hbo knew my windows software 4 62
Function after success of Jquery/AJAX action 9 28
asp.net open new page without popup blocker 8 18
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question