-
Notifications
You must be signed in to change notification settings - Fork 6k
Fixed VB code and syntax highlighting #1799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for noticing the rather bizarre language identifier, @svick. Eventually, we're planning to break this up into standalone C# and VB topics, so could you especially add the separate C# and VB code blocks for PropertyChanged?.Invoke(e)? Thanks.
``` | ||
|
||
The last example demonstrates that the null-condition operators are short-circuiting. If one operation in a chain of conditional member access and index operation returns null, then the rest of the chain’s execution stops. Other operations with lower precedence in the expression continue. For example, `E` in the following always executes, and the `??` and `==` operations execute. | ||
|
||
```vb-c# | ||
```csharp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@svick Can you add semicolons at the ends of the lines of C# code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those are not valid C# statements, so semicolons don't make sense here. I think they are just supposed to be two separate expressions.
Do you think it would be clearer if they were expanded to statements? Something like:
var maybeE = A?.B?.C?[0] ?? E;
var equalsE = A?.B?.C?[0] == E;
@@ -57,21 +59,18 @@ A?.B?.C?[0] == E | |||
var handler = this.PropertyChanged; | |||
if (handler != null) | |||
handler(…) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
handler(...);
``` | ||
|
||
The new way is much simpler: | ||
|
||
```vb-c# | ||
```csharp | ||
PropertyChanged?.Invoke(e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you break this out into two separate code blocks (even though they're basically identical)?
PropertyChanged?.Invoke(e);
PropertyChanged?.Invoke(e)
PropertyChanged?.Invoke(e) | ||
|
||
``` | ||
|
||
The new way is thread-safe because the compiler generates code to evaluate `PropertyChanged` one time only, keeping the result in temporary variable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a temporary variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rpetrusha Addressed your comments, except the one where I commented.
``` | ||
|
||
The last example demonstrates that the null-condition operators are short-circuiting. If one operation in a chain of conditional member access and index operation returns null, then the rest of the chain’s execution stops. Other operations with lower precedence in the expression continue. For example, `E` in the following always executes, and the `??` and `==` operations execute. | ||
|
||
```vb-c# | ||
```csharp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those are not valid C# statements, so semicolons don't make sense here. I think they are just supposed to be two separate expressions.
Do you think it would be clearer if they were expanded to statements? Something like:
var maybeE = A?.B?.C?[0] ?? E;
var equalsE = A?.B?.C?[0] == E;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making the changes, @svick!
I think that we can leave them. |
I noticed this bizarre identifier this morning when I opening issue #1797. It was even on MSDN: https://msdn.microsoft.com/en-us/library/9c7b2c8f-a785-44ca-836c-407bfb6d27f5! |
When reviewing #1796, I noticed that this article used the invalid language identifier
vb-c#
. I fixed that by changing it tocsharp
in one case and added a separate VB block in the second, because the code was not valid VB.While here, I also fixed other invalid VB code.