i need to develop a library.. which should be able to return values..may be as properties.. im using c# to program.. need help..
Value returned by library
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
AlanRank #669 · 3.6K reputationPosted Aug 28, 2008, 12:37 AM EDT
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 :)