I'm having memory performance issues with my code, and I'm not sure if this is the best way to pass parameters to my methods. I will give a brief example about this.
I have, for example, this class:
class Person
{
public string Name { get; set; }
public bool IsMale { get; set; }
public string Address { get; set; }
public DateTime DateOfBirth { get; set; }
}
and then I use it as follows:
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;
}
Now, in my application, I have many method calls, where the whole object (an object with a lot of properties, not like this “Personality” object from my example) was passed as a parameter, and I think to improve the code by sending methods only those the properties they need, but I'm currently not sure how this will improve memory performance.
, Peron , CalculateAge(person);, , CalculateAge(person.DateOfBirth);?
, CalculateAge(person.DateOfBirth); ( ) , , , .