My problem lies in that I have a method that takes a variable amount of parameters.
Each of those parameters are an object, the real problem lies in that it gets horribly verbose to write new ClassName(p1, p2)
for every single parameter in that method.
is there a way to send p1
and p2
as a single parameter in the form of either {p1, p2}
or (p1, p2)
?
so that I can write Insert(("John", "Doe"), ("Sherlock", "Holmes"), ... etc)
and then pass those into news in the method itself rather than writing Insert(new Person("John", "Doe"), new Person("Sherlock", "Holmes"), ... etc)
I know tuples in F# and scala can do it this way, but using tuples in C# just makes for even longer code
so is there a way to make it less verbose?
Edit: I'm not looking to create new arrays or new lists instead I want to avoid the new keyword as much as possible
Edit2: some people requested to see what my Insert method looks like; currently it looks like this:
public void Insert(params Person[] arr)
{
//inserts the person in a hash table
Action<Person> insert = (person) => _table[hasher(person.Name)].Add(person);
// calls the insert function/action for each person in the parameter array
Array.ForEach(arr, insert);
}