在Function中设置参数的默认值的小技巧

Function GetNextLineNum(ByVal _tableName As String, _
                                                      ByVal _fieldName As String, _
                                                     Optional ByVal _idFieldName As String = "", _
                                                     Optional ByVal _idValue As String = "", _
                                                     Optional ByVal _existsId As Boolean = True) As Integer

 

 

 

在Function中设置参数的默认值,需注意的是需要强制输入的参数要放在前面,不然系统会让你在所有的参数前面都加上Optional

所以不会出现以下代码

Function GetNextLineNum(Optional ByVal _idFieldName As String = "", _
                                                     Optional ByVal _idValue As String = "", _
                                                     Optional ByVal _existsId As Boolean = True, _

                                                     ByVal _tableName As String, _
                                                     ByVal _fieldName As String) As Integer

你可能感兴趣的:(VB.NET)