is it possible to have IN in a if-statement?

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

ASP.NET 2.0

This code gives me compile error:
if (menuitem.Text in {"Inbox", "Outbox" })
{
e.Item.Parent.ChildItems.Remove(e.Item);
}

Instead I could just have written the code below, but I think maybe using IN
is better..
if (menuitem.Text == "Inbox" || menuitem.Text == "Outbox" )
{
e.Item.Parent.ChildItems.Remove(e.Item);
}

Any suggestions on how to use IN in the if-statement above? is it possible?

Jeff
 
Jeff,
I suspect that you are thinking of the SQL "IN" Keyword, which is simply not
present in this form in the C# language.

if you have a large number of items, you could put them into one of the
collections or System.Collections.Generic classes and use one of the methods
like Find or Contains on it.
Peter
 
Yes, I was thinking about IN as in sql/select... anyway I have solved it now
by using:

if (menuitem.Text == "Inbox" || menuitem.Text == "Outbox" )
{
e.Item.Parent.ChildItems.Remove(e.Item);
}
 
switch (menuitem.Text) {
case "Inbox":
case "Outbox":
e.Item.Parent.ChildItems.Remove(e.Item);
break;
case "abc":
case "xyz":
// other options here
break;
}
 
Back
Top