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

Status
Not open for further replies.

peac3

Technical User
Jan 17, 2009
226
AU
Hi guys,

I have so many parameters like this code and seems repetitive, I wonder whether I can write in simpler and more elegant ways.

Code:
If (OwnerCode != Null)
{
  OwnerCode = value1;
}
else
{
   OwnerCode = string.empty;
}

If (selectedCode != Null)
{
  selectedCode  = value2;
}
else
{
   selectedCode  = string.empty;
}
 
correction, the logic is supposed to be:

Code:
If (OwnerCode != Null)
{
  value1 = OwnerCode;
}
else
{
   value1 = string.empty;
}

If (selectedCode != Null)
{
  value2 = selectedCode;
}
else
{
   value2 = string.empty;
} 
[code]
 
Code:
        value1 = OwnerCode ?? string.Empty;
        value2 = selectedCode ?? string.Empty;
[glasses]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top