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 returning a value through its declaration, while a Function returns a value of a declared or inferred return 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 returning 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 • 772 views
Visual Basic Interview questions
Advanced level • 701 views
What do Option Strict On and Option Explicit On help catch in VB.NET?
Easy level • 65 views
How do ByVal and ByRef behave when a VB.NET parameter refers to an object?
Medium level • 54 views
How would you validate integer input without using exceptions for an expected invalid value?
Medium level • 54 views