c# - VB.NET Execution Order -


i working on converting vb source code on c#. while understand there converters automate this, , use particular dll without rewriting it, i'm doing partially can understand vb better. not expect write it, it's @ least helping me able read it.

in doing though, i've come across quite confusing. following code snippets examples, i've seen throughout program.

vb source code:

friend function allocateobjectnumber() long     allocateobjectnumber = _nextfreeobjectnumber     _nextfreeobjectnumber += 1     _objectallocatedcount += 1 end function 

my translated c# code:

    internal long allocateobjectnumber()     {         cvnextfreeobjectnumber += 1;         cvobjectallocatedcount += 1;         return cvnextfreeobjectnumber;     } 

what i'm not understanding flow control vb uses. understand allocateobjectnumber += 1 used in place of return cvnextfreeobjectnumber, if line comes before incrementing of 2 variables, how code not considered unreachable? based on c# understanding, first line in method return calling method, , whole method act pseudo-property.

any helpful explanations?

the vb approach more similar storing value in temporary variable:

internal long allocateobjectnumber() {     var nextnumber = _nextfreeobjectnumber     cvnextfreeobjectnumber += 1;     cvobjectallocatedcount += 1;     return nextnumber; } 

in vb function = value syntax doesn't return - code after can keep running. when method reaches end, value used becomes 'return' value whatever called in first place.

you can use function = value syntax multiple times in same method way of returning different result in different conditions without needing temporary variable used in example.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

node.js - Bad Request - node js ajax post -

uitableview - Create and use custom prototype table cells in xamarin ios using storyboard -