2

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.

Brandon
  • 68,708
  • 30
  • 194
  • 223
  • 2
    Is it good to have long, compound statements like this? My (C++) habit would be to write that as three or four separate statements (lines of code), and let the compiler optimize it if it can and wants to. – ChrisW May 22 '09 at 17:08
  • I'm not sure if its good or not, but really it'd be two statements. One to determine the string that needs to be split, and another to actually split it. However if I did that, I'd be creating a string for no reason since I'd only need to use it a single time. Maybe it would be optimized anyway, but the people I work with prefer this as they consider it cleaner when you don't make variables you don't need. – Brandon May 22 '09 at 17:17
  • 1
    @Brandon, whether you give that variable a name or not, it will still exist. You aren't making your code any faster by making it less readable. In fact, how fast is your code right now when it doesn't even compile? That's a low-blow, but it's worth thinking about if you run into these problems often. – Wedge May 22 '09 at 17:30
  • @Wedge, I'm sure you're probably right, but as I said, its not my call to make. I do it the way its accepted. As for running into the problems often, I can't say I do. This was just a bad case of me not paying attention to what ReSharper considers redundant code. – Brandon May 22 '09 at 17:39
  • The code you have there should go through the C# compiler just fine. If you think you've found a C# compiler bug, feel free to send me a small, complete program that I can use to reproduce the problem. – Eric Lippert May 22 '09 at 19:57
  • I don't think its a bug. Isn't that .NET 3.0 syntax to leave out the type? – Brandon May 25 '09 at 14:14

1 Answers1

8

I suggest trying

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

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

mqp
  • 70,359
  • 14
  • 95
  • 123