i need to develop a library.. which should be able to return values..may be as properties.. im using c# to program.. need help..
Loading
i need to develop a library.. which should be able to return values..may be as properties.. im using c# to program.. need help..
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
AlanPosted Aug 28, 2008, 4:37 AM
Start a new C# Class Library project using VS.
Just program as normal, creating classes with properties, methods etc. However, there's no need for a Main() method as .NET dlls don't have entrypoints.
Make sure your classes are declared as public so they can be accessed by code using the library. After you've built the library, add a reference to it to an executable project so you can test it.
To make it easier to use the library classes from another project always add a 'using' directive to that project for the library's namespace. For example, suppose your library contains this class:
namespace MyLibrary
{
public class MyClass
{
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
public MyClass(string name)
{
this.name = name;
}
}
}
To use it from another project, you'd do:
using MyLibrary;
// ...
MyClass mc = new MyClass("Alan");
string name = mc.Name;
And that's all there is to it :)