locked
Cannot implicitly convert type 'char' to 'string' problem RRS feed

  • Question

  • User-2006371901 posted

    I'm just merely trying to take a querystring value, make sure its a string, then associate a string value to treecat depending on whats in the QueryString ; can't understand why it's not recognizing this as a string, getting Cannot implicitly convert type 'char' to 'string' on the qtree = '*' values

    <script runat="server" language="C#">
    string qcheck()
    {

    string qtree;
    string treecat;

    qtree = Request.QueryString["c"].ToString();

    if (qtree = '1') {
    treecat = "Citrus";
    }
    else if (qtree = '2') {
    treecat = "Shade";
    }


    return treecat;

    }
    </script>

    ???
    Ned

    Wednesday, March 7, 2018 2:28 AM

Answers

  • User177399542 posted

    Hi,

    There are two problems with your code:

    1. Use " instead of '
    2. Use double == instead of =
    if (qtree == "1") {
    treecat = "Citrus";
    }
    else if (qtree == "2") {
    treecat = "Shade";
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 7, 2018 3:15 AM