Click here to Skip to main content
15,912,932 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,
Can anybody give me an example how I can create a dll for c#.net and how I can use the dll in other programs or projects?
Thanks

I have tried after Abhinav link then use a classlibrary file and method is Add

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace math
{
    public class AddClass
    {
        public static int Add(int x,int y)
        {
        return(x+y);
        }
    }
}


and main block like this

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using math;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 2, b = 3;
            int add = AddClass.Add(a , b);
            Console.WriteLine("total", add);
        }
    }
}

Error is A project with an output type of library can not be started directly??

tell me where is wrong??
Posted
Updated 23-Nov-10 23:19pm
v4
Comments
fjdiewornncalwe 24-Nov-10 8:37am    
You need to have one project that is of type class library. That one will compile into a dll. You then add that dll as a reference to another project that can be started.(ie. WinForms, WPF, ASP.Net...). Then you can consume public classes and methods from within the dll.

1 solution

See here[^].
 
Share this answer
 
Comments
Dalek Dave 24-Nov-10 5:08am    
Good Link.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900