Solved

Anyway to keep different value types in the same array?

Posted on 2013-12-02
4
264 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
[X]
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
  • 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

624 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