Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 745
Omtechguy Avatar asked Dec 02 '12 09:12

Omtechguy


1 Answers

It all depends if you are passing it by value or reference. Typical parameters (int, float, double, bool) are all passed by value. Means they are copied. If you pass object it only "sends" pointer to object (reference) to function which is 4 or 8 bytes long.

It is more efficient to pass object if you have that many parameters.

like image 76
Hooch Avatar answered Oct 25 '22 08:10

Hooch