In this post, I would like to show how to create a class library into
project and create a class in the class library. Now let’s do it with me step
by step.
1. First you need to create a new class library by go to
Menu bar, Click on
File, and then mouse over on
Add and choose
New project. Please see picture below:
|
Figure 1: Add a new project |
2. when a
Add New Project dialog appear, in Installed Template panel --> Click on Visual C# -->Click on Class Library, and then naming your class library in Name Box. Click on Browse button if you would like to save your class library in other locations in your computer. Click Ok to finish. Please see picture below:
|
Figure 2: Create a class llibrary |
3. Now you get a new class library as you named it and also a class,
Class1.cs, by default. Please do not delete this class file unless you
create a new class. To create a new class in your Class Library, Go to
your class library in
Solution Explorer panel -->click on your class library. When the context dialog appear,
mouse over on
Add and choose
New Item… . Please see picture below:
|
Figure 3: Add new item |
4. Add New Item dialog appear, In Installed Template panel --> click on Visual C# items, and then click on Class. Rename your class in Name box --> click Add to create a new class.
|
Figure 4: Add a class into the class library |
5.
Finally, you already got a new class in your project. In this time you can
delete your default class (Class1.cs), if you would love to. Use public
keyword to declare your new class to make sure that you can call it in
other project. To do this: First, click on the class in class library
object. Second, type public keyword. Please see picture below:
|
Figure 5: Declare class as public |
6. Now let’s build your class library. In
Solution Explorer panel, right click on your class library and then choose
Build.
Done ….Now you get a Class Library in your project.
No comments: