Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simplify code pls 1

Status
Not open for further replies.

peac3

Technical User
Jan 17, 2009
226
AU
Hi guys, there are some of my codes look repetitive. I was wondering whether we could make it one liner

code]
If (OwnerCode != Null)
{
value1 = OwnerCode;
}
else
{
value1 = string.empty;
}

If (selectedCode != Null)
{
value2 = selectedCode;
}
else
{
value2 = string.empty;
}
[/code]

Cheers
 
How will this work?

Code:
value1 = !string.IsNullOrEmpty(OwnerCode) ? OwnerCode : string.Empty;
value2 = !string.IsNullOrEmpty(selectedCode) ? selectedCode : string.Empty;

Good luck!

-Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top