开发者

VB.NET: Possible to separate function into sections?

Is it possible to divide a function into sections, something like this?

Function myFunc

  Section
    Dim i As Integer = 0
    ...
  开发者_运维百科End Section

  Section
    Dim i As Integer = 0
    ...
  End Section

End Function

I realize it could be done with

If True Then
  Dim i As Integer = 0
  ...
End If

but that seems like a hack

Am I going about this the wrong way?


It sounds like you need to separate your function into... more functions.

If you do too much in one function, it can be hard to maintain. Your functions and methods should really be there to do one task or one specific function. Anything more than that and you should split it into multiple functions.

Try and thing of a literal name for the function, e.g. CreateDatabaseConnection. If you have a name like CreateDatabaseConnectionAndSelectContacts (i.e. with an 'And' in the name), it might be a candidate for refactoring.


I would recommend refactoring your "Sections" into separate functions or subs, and calling them as appropriate. The fact that you want this separate seems like it highlights an opportunity for refactoring....

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜