VB.Net is not such an old language, let’s say it saw the light in 2002, that makes it 9 years old. But it has some compatibility with VB code which makes it 20 years old. So the tech leads of the language don’t only add new things they also have to make sure the old things work and that it is compatible with C#. This sometimes has some weird consequences.
The VB code
Just look at these three functions.
```vbnet Public Function TestReturn() As String Return “test” End Function
Public Function TestNoReturn() As String TestNoReturn = “test” End Function
Public Function TestNoReturnFancy() As String TestNoReturnFancy = “test” Mid(TestNoReturnFancy, (InStr(TestNoReturn, “te”)), 2) = “pe” End Function``` Those three are all valid code.
They will return this.
That last function is kind of weird and not recommend. The latest version of Resharper 6 will even tell you it does not understand that and give an error.
With this errormessage.
Only variable or property can be the target of an assignment.
I don’t know if I should file that as a bug to the Resharper team since it is mighty ugly code and not desired.
The C# code
Luckily you can not do the above in C#. You can just do normal things.
Some things should just be deprecated and the assign to functionname is one of them.