1
Answer

Typecast an ArrayList to Struct?

Mayur M

Mayur M

16y
2.2k
1

Hi,

I have a query regarding the struct.

1) Can a method be created in a class with a return type struct? But my return type in the method should be a ArrayList?

Please find the below sample code;

Code Snippet:

The below code is giving me an error.

public Color GetRecentColor()
        {
            if (colorCollection.Count > 0)
            {
                return (Color)colorCollection[colorCollection.Count - 1];
            }
            return null;
        }

In the above code, Color is a struct and colorCollection is an ArrayList.

Is there a solution to typecast a struct to ArrayList?

Thanks in advance,

Mayur M

Answers (1)