Let’s say I have an array I need to store string values as well as double values. I know I can store the doubles as strings, and just deal with the conversions, but is it possible to use an array with two data types?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
You may use
object[]and do some type checking. You will get some boxing/unboxing when accessing the doubles, but that will be faster thandouble.Parse()anyway.An alternative is to create a class with both types and a marker:
and then create an array of StringOrDouble. This will save you from some typechecking and boxing, but will have a larger memory overhead.