GoldenGaming

Welcome to GoldenGaming. We appreciate your support and hope that you be an active member. Don't Forget To Sign Up!

Welcome to Golden Gaming
Contact an Admin or Moderator for any issues you have
We Are Purchasing A Domain After 100 Members!
You can now use symbols in your username, just don't forget them!

    [C#] How to make a DLL

    Share
    avatar
    I Am Programmer
    Rookie User
    Rookie User

    Posts : 20

    [C#] How to make a DLL

    Post  I Am Programmer on Wed Dec 08, 2010 6:54 pm

    Hey, I Am Programmer here, teaching you how to start constructing a DLL! Just follow this basic tutorial and you will have created your first DLL and be on your way to creating more!
    Step 1: Create a new project:



    Make sure it is a Class Library, as that is what a DLL is, a Dynamic Linking Library

    Step 2: Start building your code!
    Okay, after you have started your new project file in Visual C# Express, we are going to start adding our code. I am just going to type up a basic script to show basic method creation:

    Code:

    public bool isRightTriangle(double leg1, double leg2, double hypotenuse)
    {
    if ((leg1 * leg1) + (leg2 * leg2) == (hypotenuse * hypotenuse))
            return true;
            else
                    return false;
    }

    Now I am going to go and explain this code piece by piece:

    Code:

    public /*method identifier*/
     bool /*return type (boolean variable (true/false))*/
    isRightTriangle(
    double leg1 /*argument 1, double variable*/,
    double leg2 /*argument 2, double variable*/,
    double hypotenuse/*argument 3, double variable*/
    )
    {
    if ((leg1 * leg1) + (leg2 * leg2) == (hypotenuse * hypotenuse)) //this just calculates the pythagoream theorum based on the leg lengths and the hypotenuse length
    return true; //if the triangle is a right triangle, return the boolean value: true
    else
    return false; //otherwise, return the boolean value false
    }

    Make the sense?
    Now if you don’t want the method to return a value, instead of the return type, you would put void, as in void of return.

    Step 3: Renaming
    Your going to want to rename your class name’s so instead of Class1, it’s the name of what you want it to be, if that makes sense O_o
    So your going to change this:




    Change both of these like I did.


    Step 4: Compile.
    Just debug the project, you will get this error message:



    That’s okay though. Your DLL will be produced in your Debug folder within your project folder.

    Step 5:
    Use your new DLL!
    The usage of your DLL will be this:

    Code:
    YourClassName variableName = new YourClassName();

    And to access the methods of your class, you just put a dot ‘.’ After your variable name and the methods should pop up in visual studio
    And your done!

      Current date/time is Fri Nov 17, 2017 10:53 pm