I have an Employee
class:
class Employee
{
string FirstName { get; set; }
string LastName { get; set; }
}
Sometimes I want to get the full name and it's tedious to write emp.FirstName + emp.LastName
again and again and again.
Is it bad practice to add a FullName
property (because it's the same data twice or something)?
class Employee
{
string FirstName { get; set; }
string LastName { get; set; }
string FullName => $"{FirstName} {LastName}";
}
}
It's not the same data twice, you are actually cutting down on repeated code by adding this.
It would be bad if FullName wasn't calculated and it had to be maintained (kept in sync, set etc.) alongside FirstName/LastName.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With