Is there a VB.NET equivalent of C# out parameters?

后端 未结 7 953
野性不改
野性不改 2020-11-30 06:22

Does VB.NET have a direct equivalent to C# out function parameters, where the variable passed into a function does not need to be initialised?

7条回答
  •  悲&欢浪女
    2020-11-30 06:51

    No, there is no equivalent construct that allows a non-initialised variable to be passed to a method without a warning, but, as mentioned in my question and answer specifying an attribute on a ByRef parameter definition, although VB ignores it, is treated by C# as an out parameter.

    So, I would pre-initialise reference variables to Nothing and specify ByRef to signify the intention (that will work if C# users ever access your methods).

    If you feel you know when you intend to access the default Nothing in otherwise unassigned reference variables you can set the "Warning configuration" "Use of variable prior to assignment" to "None" at the Project level (Project Properties > Compile, and you probably want to set Configuration to "All Configurations" before changing this setting), or, in VS2015 (VB.NET 14), you can use #Disable Warning BC42030.

提交回复
热议问题