Part of the
You Can Learn C# series.
By Ken Brown
Editor, YouCanLearnSeries.com
Updated: August 31, 2004
This is a two part article on
creating a class in Visual Studio.
Create a Class
Using a Class
One of the basics to good object oriented programming is the use of classes to
control access to objects and provide reusable code, which is easy to maintain.
This tutorial covers the basic task of creating a class using Visual Studio.
After following the simple steps presented, you will easily create your own
class and be able to instantiate the class on a WebForm.
Let's get started creating our C# class...
1. Open Visual Studio
2. Choose New Project
3. Choose Visual Studio Solutions / Blank Solution
4. Type in the name "CreateClass" / Click on the Okay button.

5. Right Click on the new solution you just created, found in the Solution
Explorer tab.
6. Choose menu item Add / New Project
7. Choose Project type of Visual C# Projects
8. Choose Template type of Asp.Net Web Application
9. Type in a location of "http://localhost/CreateClass/YCLSProj1"

10. Choose OKAY, This will create a new Web Project on your local harddrive in
"C:\inetpub\wwwroot\createclass\YCLSproj1"
Now you are ready to add a new class.
1. In Solution Explorer, right click on your Project. (YCLSProj1)
2. Choose menu item "ADD" / "Add Class"
3. The dialog box that opens will already have "Web Project Items" chosen with
the "Class" template highlighted.
4. You need to change the class name to "Friends.cs", then choose the "Open"
button.

5. That will create a new class ...
public class Friends
{
}
6. You also see the constructor for the class
public Friends()
{
}
7. Create a couple of variables.
Above the constructor for the class add two public variables.
public string id;
public string name;
8. Now create a new public constructor using the variables you just created.
public Friends(string id, string name)
{
this.name = name;
this.id = id;
}
Go To Page 1 /
2
|