Opposite of "is"

Posted on 2007-07-26
Last Modified: 2007-07-26
What would be the opposite?  (ie (if page not INonSecure page)

            if (Page is INonSecurePage)
                //do some stuff
Question by:JRockFL
    LVL 8

    Expert Comment

    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.


    LVL 22

    Expert Comment

    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.

    LVL 22

    Expert Comment

    BTW - Since this appeared in the C# zone, I assumed C#.
    LVL 22

    Accepted Solution

    is operator does not compare values, but types.

        if (!(Page is INonSecurePage))

    should do it.
    LVL 8

    Author Comment

    Thank you DarkoLord, that is what I needed.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now