I am stuck in something. I want to convert this object, which is a array of objects, into a array of strings I cannot find a good way to do that. Do I need to use a for loop? If someone can also tell me why these 2 methods failed, I will appreciate.
object greetings = new object[] { "hi", "hello", "greetings" };
if (greetings.GetType().IsArray)
{
//string[] arr = greetings as string[];
//string[] arr = (string[])greetings;
}
var asArray = ((object[])greetings).Cast<string>().ToArray()greetingsto an array of strings is not valid. You don't have an array of strings. You have an array of objects (where all of the objects happen to be strings).