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.
- Classes and Objects
- The Stack and the Heap
- Defining a Class and Creating an Object
- Defining Accessibility and Scope
- Passing Parameters to a Method
- Overloading Methods
- Using Constructors
- Static Class Members
- Namespaces and XML Commenting
- 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.
- Add a new class to the login project from last time called UserLogin.
- Create one public property called username, and one private property called password.
- Create a couple of overloaded constructors, one for no info, one if username is passed, and one if the username and password are passed.
- Create a public method called Login that passes the username and password and returns a boolean value depeding on whether the login was successful.
- 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.
- Be sure to add XML commenting to any methods you decide to create.
- 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.