In VB.NET, how do Sub and Function differ?
Interactive Practice Mode
Formulate your thoughts or take notes before revealing the model solution.
Saved automatically
Model Answer & Deep-Dive Explanation
A Sub performs an operation without retu ing a value through its declaration, while a Function retu s a value of a declared or inferred retu type. Both can accept parameters and can have observable effects. Choose a Function when the caller needs a result, such as a calculated total, and keep the type explicit in public APIs. A Sub can still modify shared state or an argument through ByRef, so retu ing nothing does not mean doing nothing. These questions use VB.NET rather than legacy VB6 unless stated otherwise.
Related Questions in Visual Basic
VB 6, COM, DCOM, Microsoft platform interview questions
Advanced level • 727 views
Visual Basic Interview questions
Advanced level • 643 views
How do ByVal and ByRef behave when a VB.NET parameter refers to an object?
Medium level • 2 views
Why should VB.NET file handling use a Using block?
Medium level • 2 views
How would you validate integer input without using exceptions for an expected invalid value?
Medium level • 1 views