Using Enums As Return Values from Methods

A common usage of enumerations is representing different results from methods that return a numeric value, as often happens for methods that return a number for communicating the result of the code. Consider the following code, which defines an enumeration that a method uses to communicate the result of a simple elaboration on a file:

Public Enum Result    Success = 0    Failed = 1    FileNotFound = 2End EnumPublic Function ElaborateFile(ByVal fileName As String) As Result    Try        Dim text As String = My.Computer.FileSystem.ReadAllText(fileName)        'Do some work here on your string        Return Result.Success    Catch ex As IO.FileNotFoundException        Return ...

Get Visual Basic 2015 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.