You must Sign In to post a response.
  • Category: .NET

    Hi to all ,pls give the proper solution of below error message.

    C# STATEMENT : if( (curNode2.Attributes[2].Value == " Currency") || (curNode2.Attributes[2].Value == "DateTime ") || (curNode2.Attributes[2].Value = "image") || (curNode2.Attributes[2].Value = "int"))

    ERROR MESSAGE:Operator '||' cannot be applied to operands of type 'bool' and 'string'
  • #583356
    Use == instead of =. = is Used for ssignemnt and == is used for comparison.

    Please check the following code:


    if( (curNode2.Attributes[2].Value == " Currency") || (curNode2.Attributes[2].Value == "DateTime ") || (curNode2.Attributes[2].Value = "image") || (curNode2.Attributes[2].Value == "int"))


    Thanks & Regards
    Paritosh Mohapatra
    Microsoft MVP (ASP.Net/IIS)
    DotNetSpider MVM

  • #583366
    Please change them as


    if( (curNode2.Attributes[2].Value.ToString() == " Currency") || (curNode2.Attributes[2].Value.ToString() == "DateTime ") || (curNode2.Attributes[2].Value.ToString() = "image") || (curNode2.Attributes[2].Value.ToString() = "int"))

    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM

  • #583407
    try this code



    if( (curNode2.Attributes[2].Value.ToString() == " Currency") || (curNode2.Attributes[2].Value.ToString() == "DateTime ") || (curNode2.Attributes[2].Value.ToString() == "image") || (curNode2.Attributes[2].Value.ToString() == "int"))


    hope this will help you

  • #583433
    '=' operator cannot be applied for comparing. Instead use '=='

    e.g.

    string att = curNode2.Attributes[2].Value.ToString().ToUpper().Trim();
    if( att=="CURRENCY" || att=="DATETIME")) || att=="IMAGE" || att=="INT" )
    {
    ...
    }

    You can also use following approach

    string att = curNode2.Attributes[2].Value.ToString().ToUpper().Trim();
    if( att.Equals("CURRENCY") || att.Equals("DATETIME") || att.Equals("IMAGE") || att.Equals("INT") )
    {
    ...
    }

    Thx!!
    Sharad

  • #583435
    Also refer this URL...

    ( When should I use == and when should I use Equals? )

    http://blogs.msdn.com/b/csharpfaq/archive/2004/03/29/102224.aspx

    Thx!!
    Sharad

  • #583465
    try this above code

    if( (curNode2.Attributes[2].Value.Tostring() == " Currency") || (curNode2.Attributes[2].Value.Tostring() == "DateTime ") || (curNode2.Attributes[2].Value.Tostring() = "image") || (curNode2.Attributes[2].Value.Tostring() = "int"))

    Regards,
    Prasad.g


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.