C# - Passing 3 parameters vs passing object with 30 properties -

c#, function, memory-management, parameters, performance

Solution

You should not decide this on the basis of performance. The performance difference is so minimal to be negligible. (But to answer your question, passing the object is faster if it’s a reference type; passing the parameters is faster if the large object is a value type.)

You should decide this on the basis of what your code means. If the method is logically related to the object with 30 properties, then it makes sense for the method to take the object. You might also want to think about whether any future changes to the method might need access to more of the properties.

If the method is logically unrelated to the object, and the three values you pass in are just pieces of information for the method, you should pass them in as separate parameters. You should also think about whether any future code calling the method may want to pass in different values than those three properties from that specific object.

Problem

I was wondering, which way is better in terms of performance and memory usage? Passing only the needed parameters for a specific function or its the same to pass an object with 30 properties but the function will use 3 of them?

Original source