C# Method Overload vs Param Keyword?

You needn't loop: void Foo(params string args) { tsk. Run(String. Join(" ", args)); }.

Nice, I just learned something useful. Thanks! I thought I would know String by now.

– atticae Jan 21 at 10:42 actually its tsk. Run(String. Join(" ", args)); – Valentin Kuzub Jan 21 at 10:42 @Valentin Haha oops!

– Matt Hamilton Jan 21 at 10:44.

If you know the number of arguments use overload as it will be more efficient. The compiler will be able to directly call the right method and you can assign default values. If the paramlist is created dynamically and can vary more in length, use params.

Or in you example skip params and just use a string list or string array.

Well you could do that by using (params object parameters) then inside method create a Strigbuilder and append each param from list to it in your required fashion. Its unclear whether your parameters are all strings, or they are really various by type and object signature should be used. If parameters are different by type I think having params method with objects would create more problems than help.

If they are all strings I think params is ideal solution for this situation.

Void foo( params string parameters ) { StringBuilder sb = new StringBuilder( ); foreach ( string parameter in parameters ) { sb. Append( parameter ); sb. Append( " " ); } tsk.

Run( sb. ToString( ) ); }.

2 init sb first ;) – Valentin Kuzub Jan 21 at 10:39 Of course :D Ah ha ha ha - typing too quickly! – Nick Jan 21 at 10:40.

Like this: void foo<T>(params T parameters) { tsk. Run(string. Join<T>(" ", parameters)); }.

Now the parameters with the tsk. The parameters will form one continuous string that is used in a command line app. At most, there will be 4 parameters, so is it best to do an overload method for each.

Or is there a way using the Param keyword to take the parameters and add them to the tsk.run() method. Would it be worth using param and then looping through, concatenating into a string and then put that into run?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions