C # compilation question: newlines in 1 expression throwing an error
Simple question
Consider this piece of code in C #
String a;
String b;
String c;
1. a =
2. b =
3. //Comment
4. c = "a String";
At compile time it was fine, but I got into an error when starting the application. From my logs, the error occurs with the above.
Question:
Is the error caused by the comment on line 3?
Error: "Object reference not set to object instance"
I assume the compiler treats the above code as an instruction.
This code is in the code behind the aspx page. (Aspx.cs)
// Background //
Aspx was tested on test servers and was a. However, after we deployed the page to the production server, there was an error in pageload (), the line where the error occurred is on line 1 of my example code above.
It's just my suspicion that the comment was causing the error.
I'm right?
source to share
The original code was not legal. Your edited code is fine; all 3 variables are assigned the same string ("string").
What exact error are you seeing?
(question updated to include "Object reference not set to object instance")
This error has nothing to do with the code posted (unless you provided the code on embed) and has nothing to do with the comment //
. You need to look elsewhere. Try looking at the stack trace or typing debug / output messages. Or just step through the code to see where it really explodes.
source to share
The compiler ignores everything to the right of the "//" on line 3, but lines 1, 2, and 4 are still part of the same statement (as does everything below line 4 before the ";" or block).
Unless your code of code has lost something while posting it, that code shouldn't even compile (parse error).
Ok, with your edited code, the syntax is valid and shouldn't be the cause of your error. Submit a bug ...
source to share