Best way for memory to pass method parameters
<p>I am experiencing some memory performance issues with my code and I am not sure which is the best way to pass parameters to my methods. I will give a short example about this.</p>

<p>I have for instance this class:</p>

<pre><code>class Person
{
    public string Name { get; set; }
    public bool IsMale { get; set; }
    public string Address { get; set; }
    public DateTime DateOfBirth { get; set; }
}
</code></pre>

<p>and then I am using it like this:</p>

<pre><code>    static void Main(string[] args)
    {
        Person person = new Person {
            Name = "John",
            Address = "Test address",
            DateOfBirth = DateTime.Now,
            IsMale = false };

        int age = CalculateAge(person);

        int age2 = CalculateAge(person.DateOfBirth);
    }

    private static int CalculateAge(Person person)
    {
        return (DateTime.Now - person.DateOfBirth).Days;
    }

    private static int CalculateAge(DateTime birthDate)
    {
        return (DateTime.Now - birthDate).Days;
    }
</code></pre>

<p>Now in my app I have lots of method calls where the entire object (an object with lots of properties not like this "Person" object from my example) was passed as parameter and I am thinking to improve the code by sending to the methods only the properties that they need, but currently I am not sure how this will improve memory performance.</p>

<p>How is it better regarding memory usage, to send the entire Peron object to my method like <code>CalculateAge(person);</code> or to send just the property that is used into the method like <code>CalculateAge(person.DateOfBirth);</code>?</p>

<p>First I thought that calls like this <code>CalculateAge(person.DateOfBirth);</code> (sending as parameters only the needed properties instead of the entire object) are using less memory but in the end after tests I noticed that app performs slower, and now I am not sure if these changes or others were slowing down my app.</p>