[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1002
  • Last Modified:

Opposite of "is"

What would be the opposite?  (ie (if page not INonSecure page)

            if (Page is INonSecurePage)
                //do some stuff
0
JRockFL
Asked:
JRockFL
1 Solution
 
bramsquadCommented:
Are you talking about VB or C#

depending on if something returns a boolean value or if its comparing values you would do this

// compare values (Page does not equal INonSecurePage)

if ( Page != INonSecurePage)
{ //do stuff }

// boolean

if ( !Page )
{  // do stuff }

VB is going to have different syntax, let me know if thats what you want.

Thanks

~b
0
 
JimBrandleyCommented:
You can do what you need with a cast.
INonSecure nsPage = Page as INonSecure;
if (nsPage != null) //The cast succeeded
{
   // do stuff
}
else // the cast failed
{
   // do other stuff
}

Using as gives you a cast that will not throw exceptions. Returns null if the cast is invalid.

Jim
0
 
JimBrandleyCommented:
BTW - Since this appeared in the C# zone, I assumed C#.
0
 
DarkoLordCommented:
is operator does not compare values, but types.

    if (!(Page is INonSecurePage))

should do it.
0
 
JRockFLAuthor Commented:
Thank you DarkoLord, that is what I needed.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now