Stav
Stav

Reputation: 3

How to get back a Size from a 2d object array in C#?

I declare a 2d array.

object[,] tbl = 
{
                { new Size(140,112), new Point(20,20) },
                { new Size(140,112), new Point(160,20) }
            
};

I am looping through the array

for(int i=0; i < tbl.GetLength(0); i++)
{

}

How do I get back the Size and Point within the loop?

Upvotes: 0

Views: 51

Answers (1)

SpockPuppet
SpockPuppet

Reputation: 140

Like this:

Size size = (Size)tbl[i, 0];
Point point = (Point)tbl[i, 1];

But it's better not to use object like this because of all the casts. Create your own class with a Size and Point property, or use a Tuple<Size, Point>.

Upvotes: 1

Related Questions