Presentation is loading. Please wait.

Presentation is loading. Please wait.

These materials where developed by Martin Schray. Please feel free to use and modify them for non-commercial purposes. If you find them useful or would.

Similar presentations


Presentation on theme: "These materials where developed by Martin Schray. Please feel free to use and modify them for non-commercial purposes. If you find them useful or would."— Presentation transcript:

1 These materials where developed by Martin Schray. Please feel free to use and modify them for non-commercial purposes. If you find them useful or would like to suggest corrections or enhancements please drop me a note at martin@martischray.com Martin Schray http://www.martinschray.com martin@martinschray.com

2 VB.NET - Enumerations Copyright Martin Schray 1997- 2003

3 Enumerations Enumerations a simple way to strongly type – type information For example, the type of arguments for a messagebox or the types of loans available or any other argument type Good for when you a known list of aguments loans or messagebox icon types

4 Enumeration declaration Example Public Enum MessageTypes Informational Warning Emergency WorldEnding End Enum

5 Enum Use Example Public Class Form1 Inherits System.Windows.Forms.Form Public Enum MessageTypes Informational Warning Emergency WorldEnding End Enum Public Sub DisplayMessage(ByVal t As MessageTypes, ByVal s As String) If t.IsDefined(t.GetType, t) Then Debug.WriteLine(t) MessageBox.Show("Your message :" & s) Else ' display message, but probably should be an exception MessageBox.Show("Invalid Message Type :" & t) End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click DisplayMessage(MessageTypes.Emergency, "world ending") DisplayMessage(7, "world ending") End Sub End Class

6 Enum comments Enum could be in a separate class Enum helped protected DisplayMessage from invalid arguments Enum used extensively in VB.NET (messagebox message types and such) When declared intellsense helps user fill in the right values


Download ppt "These materials where developed by Martin Schray. Please feel free to use and modify them for non-commercial purposes. If you find them useful or would."

Similar presentations


Ads by Google