Search code examples
c#arraysvariants

Array of Variants in c#


In c#, I want declare a function with a Dinamic array that receive any type of data primitive types like (string, integer, doubles, datetimes ....) but this types are not a Object , just a basic types. There is someway to do this ?


Solution

  • The code above works, but Have a Limitation, he don't works with diferentes types of data like a

    MyFunc(new[] {"alpha", 123, 01-02-2002});

    This code below works with string, int and date

    public bool ArrayVariant(string pQuery, ICollection collection)
    {
    
            foreach (var item in collection)
            {
                 //do something with item
            }
    }
    

    and to call function

    ArrayVariant( "any data", new dynamic[]  {"teste", 0, DateTime.Now});