Question

If something is being passed into a method as object[] myparams, each element needs to be accessed as myparams[0], myparams[1], etc.

Is there some way to provide more meaning to each index rather than just a number? Something perhaps similar to named parameters, which I know don't work for arrays.

For example:

employeeid = myparams[1]; employeeFirstName = myparams[4]; employeeAddress = myparams[6];

You would have to know that indexes 1, 4, 6 actually refer to those values.

As an additional note, object[] is bound by an interface so there isn't a way to switch out the type.

Was it helpful?

Solution

You should use key-value collection (i.e Dictionary, HashSet) rather than pure array of objects to achieve desired effect.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top