0

I have an object array that has 8 entries in it from value 0 to 7. All of the values are pretty standard, but the value in the [7, 0] spot is a string and for [7, 1] it is another object with two entries, [0, 0] and [0, 1].

My question is, I am trying to assign the object in the [7, 1] spot to a separate object array and then am pulling the [0, 1] string value from that object. My syntax for assigning the 7th spot array to another array keeps coming up null though. What is the correct syntax for either A) Assigning that object to a usable object B) Or just flat out pulling the value from the [7, 1] array and the [0, 1] inner object to a string?

I am using this right now: object[,] checkCD = param[7, 1] as object[,]; which is coming up null, I would rather just get the string from the inner object flat out but help!

4
  • 4
    I think it would be clearer if you post some code. Commented Apr 21, 2011 at 20:48
  • What code? I mean, it's an object array with an object in the [7, 1] spot instead of a string, int, etc value. I would think that should explain everything. Inside that object is a string in the [0, 1] spot I need. Like for real, what can I post that would make that any clearer, do you really need to see the variable names of the things assigned to it to understand what I'm talking about? If so you probably can't help me anyway. Commented Apr 21, 2011 at 20:53
  • 2
    Maybe if you made the types more explicit. It looks like you're talking about nested multidimensional arrays but it's not entirely clear. It doesn't matter what the variable names are but type declaration and sample data can help. It doesn't matter how well you write, English isn't anywhere near as exact as code. Commented Apr 21, 2011 at 20:55
  • 1
    As an aside: problems like this is why classes should be preferred to arrays for structured data (when possible). Commented Apr 21, 2011 at 21:17

3 Answers 3

1

For what I could understand of your question, if after executing this line

object[,] checkCD = param[7, 1] as object[,];

checkCD is null, then it means that param[7, 1] does not contain an object[,], but something of another type (or null).

Try instead

object x = param[7, 1];

and check what's the type of x - maybe you just put in [7,1] the wrong thing. If after this, x is null then it means that param[7, 1] is really null.

Sign up to request clarification or add additional context in comments.

1 Comment

This worked but I changed it a little to be object[] checkArray = param[7, 1] as object[]; since the original code gave me an error in the confines of my program. TY
1

This works for me, am i missing anyting.

object[,] array1 = new object[8,2];
            
            array1[7,1] = new object[1,2] { {"00","01"}};
            array1[7,0] = new StringBuilder("Initialized");

         object[,] seventthobj = (object[,])array1[7, 1];

enter image description here

Comments

0

Assignment should be param[7,1] = new object[,] {{value, "string"}};.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.