Creating a Class

tehon3299

Centurion
Joined
Jan 6, 2003
Messages
155
Location
Liverpool, NY
I am just getting into writing classes with .NET and I was wondering how I would do that following? I need a class that has 3 integer number (for serial keys) and it needs to have a validate function to validate the keys. I just need help on what goes in which methods. Like what is the new() method for and do you need to have one?
 
HAve 3 memeber variables for each part of the key.

You could make two contructors, one to take a string of the whole key and then chop it and, and one to take each part of the key as 3 arguments. its allways good to have multiple contructors :)

Then do something like

Dim myKeyDecoder As New keyDecoder("5535-5353-5353")

or

Dim myKeyDecoder As New keyDecoder(5535, 5353, 5353)

This will work if you make one new method overload (!?) the other.
 
You do not explicitly need a new() method, but they are usually helpful.

The new() methods are often called "Constructors". They are being executed whenever someone creates a new instance of the object.

By giving parameters to the new() method and setting the parameterless new() to private, you can assert that certain values are *always* known, when a new instance of the class is to be created.
 
apparently (acording to java people) it is allways good practice to have blank contructors to then have set get methods for the stuff in the contructor, but im not so much a fan of that.

PS good description Heiko.
 
Back
Top