if (string = string) error converting string to bool

Posted on 2004-11-03
Last Modified: 2010-04-17
I'm from a back ground and not sure how to compaire two string values in a if statement.
I know that in c# that if statements always return a boolen value and thats fine but i just want to make sure two string have the save value.
Question by:j_tipps
    LVL 9

    Accepted Solution

    are you using the double == for comparison

    if (string == string)


    if (string = string), which is assignment..

    Author Comment

    oo crap that was it, thanks man
    LVL 5

    Expert Comment

    in C#? Remember strings are objects. You can type:

        if( myStr1.Equals( myStr2 ) ) { ... }

    Which I believe is exactly the same

        if( myStr1 == myStr2 ) { ... }

    but clear in the sense that you are asking the myStr1 object to tell you whether myStr2 represents the same object.

    This works for any object, not just strings.


    Author Comment

    ya thansk for the 411 Dave!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Suggested Solutions

    Title # Comments Views Activity
    bunnyEars challenge 6 45
    powerN  challenge 3 34
    python question 5 36
    groovy example issue 10 31
    INTRODUCTION We all know how to code. But at times you simply want to insert a common code block into your existing code and amend it as per your requirements. This tool not only saves you time but also saves you the pain of typing it all out aga…
    Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    758 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

    11 Experts available now in Live!

    Get 1:1 Help Now