I don't know what everyone calls this but how do I make this piece of code shorter??
I was taught to not repeat code and at the GetAddress() method the if statement I repeat the same line twice, once from the if statement and then another from the else if statement below it
(_CClientFirstName == "John" || _CClientLastName == "Jenkins" || _CClientAge == 21)
How would I do this with less code? Im just wondering if it's possible because if it is, I would love to know. Also, please don't reply with anything too complex as Im only starting out, but if you do then try to explain it as much as you can thanks.
class ClientInfo
{
private string _CClientFirstName = "Default";
private string _CClientLastName = "Default";
private int _CClientAge = 99;
public ClientInfo(string FullName, string LastName, int Age)
{
_CClientFirstName = FullName;
_CClientLastName = LastName;
_CClientAge = Age;
}
public string GetAddress()
{
if (_CClientFirstName == "John" || _CClientLastName == "Jenkins" || _CClientAge == 21)
{
return $"{_CClientFirstName}'s address is: 67 Smokey Lane, London, B78 9JN, United Kingdom";
}
else if (_CClientFirstName == "Matt" || _CClientLastName == "Benks" || _CClientAge == 25)
{
}
}
}
Aucun commentaire:
Enregistrer un commentaire