Thursday, April 28, 2011

Why does the compiler have a problem with this line of code?

The entire solution builds fine in Visual Studio, but when I run the Nant script to compile the website I get several errors on this line:

string[] qs = (Request.QueryString["e"] ?? String.Empty)
               .Split(new[] { '?' }, StringSplitOptions.RemoveEmptyEntries);

First one says Type Expected, then Syntax error (value expected), ) expected, ; expected, etc. I've used lines like this before in the project and it doesn't seem to complain on those ones.

I'm pretty sure the error is coming from calling Split on that conditional statement, but I'm not sure why.

From stackoverflow
  • I suggest trying

    string[] qs = (Request.QueryString["e"] ?? String.Empty)
        .Split(new char[] { '?' }, StringSplitOptions.RemoveEmptyEntries);
    

    Note that new[] went to new char[].

    Brandon : Curse you, ReSharper. Thanks, that worked.

0 comments:

Post a Comment