I have a list of objects (their types are unknown ahead of time). The example below shows hard coded values, but my actual code populates the args list by reading from a CSV file. I then want to pass this list of args to a typical method that asks for certain parameters. So I cast the elements to the required types as shown. I'm getting error:
Specified cast is not valid
when the method is called at run time. How should I go about accomplishing this?
var args = new List<object>();
args.Add(5495);
args.Add("String1");
args.Add(10133);
args.Add("String2");
result = request.GetCustomer((long) args[0], (string) args[1], (int) args[2], (string) args[3]);