Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have object as parameter in function.

i want to convert that to array of string

how to do that
Posted

1 solution

One example is described on following below

C#
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            //object method casted to string array object
            string[] StringArray = Cast(GetStringArray(), new { MyList = new string[] { } }).MyList;
            foreach (string item in StringArray)
            {
                Console.WriteLine(item);
            }
            Console.ReadLine();
        }
        static object GetStringArray()
        {
            //Creating a Annonymous array string type here which is returning a object type
            return new { MyList = new string[] { "Code", "Project", "Question", "Answer" } };
        }
        //Cast object to a specific return type.
        static T Cast<T>(object obj, T Type)
        {
            return (T)obj;
        }

    }

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900