Monday, August 10, 2009

C# Conditions in 2 different ways

Checking condition in 2 different way

One Way is
if (item.Text.ToString() == "Professional")
query1 = "P";
else
query1 = "C";

--------
query1 = item.Text.ToString() == "Professional" ? "P" : "C";

================Separate
if (item.Selected == true)
query1 = item.Text.ToString() == "Professional" ? "P" : "C";
---------
if (item.Selected != true) continue;
query1 = item.Text.ToString() == "Professional" ? "P" : "C";

No comments: