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

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
 
G

Guest

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
 
J

Jeff

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);
}
 
A

Andrew Robinson

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,052
Members
48,769
Latest member
Clifft

Latest Threads

Top