mousemat24
asked on
Show details based on values
Hi there
Wonder if you can help
I have these string, any of which can be blank:
private string GetContactDetails(User user)
{
string contact = string.Format("Contact:\t{ 0}\r\n", user.FullName);
string email = string.Format("Email:\t{0} \r\n", user.Email);
string phone = string.Format("Phone:\t{0} \r\n", user.Phone);
}
what I want to to return a string based on the values above i.e.
if contact and email has a value
show:
Contact: Rob
Email: asdasd@hotmail.com
or if none of them have values, dont return any text
or if ONLY the phone has a value, show
Phone: 0283834757
etc
hope this makes sense?
thanks
Wonder if you can help
I have these string, any of which can be blank:
private string GetContactDetails(User user)
{
string contact = string.Format("Contact:\t{
string email = string.Format("Email:\t{0}
string phone = string.Format("Phone:\t{0}
}
what I want to to return a string based on the values above i.e.
if contact and email has a value
show:
Contact: Rob
Email: asdasd@hotmail.com
or if none of them have values, dont return any text
or if ONLY the phone has a value, show
Phone: 0283834757
etc
hope this makes sense?
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
string contact = user.FullName == "" ? string.Empty : string.Format("Contact:\t{
string email = user.Email == "" ? string.Empty : string.Format("Email:\t{0}
string phone = user.Phone == "" ? string.Empty : string.Format("Phone:\t{0}