Learning C# Part 4: Classes and Objects

Written By: Kevin Jordan

- 14 Oct 2006 -

Description: This series aims to take a beginning programmer to an intermediate level in C#. Topics covered in Part 4 include: classes and objects, accessibility and scope, methods, constructors, static class members, namespaces, and XML commenting.

  1. Classes and Objects
  2. The Stack and the Heap
  3. Defining a Class and Creating an Object
  4. Defining Accessibility and Scope
  5. Passing Parameters to a Method
  6. Overloading Methods
  7. Using Constructors
  8. Static Class Members
  9. Namespaces and XML Commenting
  10. Aww Man... Not Homework

Aww Man... Not Homework

So I know we covered a lot this time around, but the more you know about classes, the better you'll be at creating reusable code. Say we actually finished our Client class, we should be able to use it on any programs that require keeping track of clients, and that'll save you a lot of time on future projects.

This week we're going to expand on our login system from last week. If you didn't finish it, don't worry. Download the code from this article and it'll have the solutions to both of the last homework problems.

  1. Add a new class to the login project from last time called UserLogin.
  2. Create one public property called username, and one private property called password.
  3. Create a couple of overloaded constructors, one for no info, one if username is passed, and one if the username and password are passed.
  4. Create a public method called Login that passes the username and password and returns a boolean value depeding on whether the login was successful.
  5. As extra practice, add a public static string for invalid and successful login attempts. Use this member to display the appropriate message when someone tries to login.
  6. Be sure to add XML commenting to any methods you decide to create.
  7. And of course, create a couple instances of the UserLogin class, and make it work.

This wraps up the extremely long introduction to classes. Can you believe that advanced object oriented techniques is going to be covered next? Good luck.

<< Previous