DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Trending

  • Chat With Your Knowledge Base: A Hands-On Java and LangChain4j Guide
  • GitHub Copilot's New AI Coding Agent Saves Developers Time – And Requires Their Oversight
  • The Future of Java and AI: Coding in 2025
  • MCP Servers: The Technical Debt That Is Coming

C# – Creating a DLL to Hide Your Code

By 
Sourabh Sharma user avatar
Sourabh Sharma
·
Mar. 06, 13 · Interview
Likes (0)
Comment
Save
Tweet
Share
34.2K Views

Join the DZone community and get the full member experience.

Join For Free

The DLL also called Dynamic Link Library is a file that can be used dynamically by other programs. We create the DLL mainly to hide our confidential code so that we can use the code everywhere but can not see the code. When we talk about the layers or 3 and above tier application we need to understand one thing that why we create layers in our project. We only show some part of code to everyone and hide the main coding part. The benefit is we can use this code but can not see this.

Advantages of creating DLL: 
There are many advantages of using the DLL in your Application but We are talking about the main advantages: 
1. DLL is used to hide the code so anyone can use the functionality but no one can steal the code.
2. Once we create a DLL then it can be used in many applications. We just have to import that dll into our project.
3. Adding a dll into your project is very simple. It reduces time to write the code again and again. In C#.Net you need to just import dll with add reference in your project. 
Now we will see that how we can create a dll and then how the dll can be used in the application. Creating DLL: 
Step 1: Open Visual Studio and Create New Project by Clicking New->Project 
1  

Step 2: Select 'Class Library' from the list and click Ok. 
2

Step 3: Now you will see the following screen
3

Step 4: Change the name Class1. As I have changed the Name with MyCode and Write the code what you want to use in your DLL.
4 

Step 5: Now Click Build Menu -> Build Solution to complete the process. Now you can see the dll file with .dll extention inside you project folder. Now the dll is ready to use inside other application.

Step 6: Create a New Project. Then Right click on Project Name -> Add Reference -> Select the dll File to add as reference into your project.

5

Step 7: Now you need to include the namespace for that dll by using the following code.
using ClassLibrary2;
Step 8: Now you can access the method of that dll and the code will be hidden to you. You can access the method of dll file by using the following code.

private void button1_Click(object sender, EventArgs e)
        {
            int x, y;
            x = Convert.ToInt32(txtNo1.Text);
            y = Convert.ToInt32(txtNo2.Text);
            MyCode ob = new MyCode();
            int c = ob.sum(x, y);
            txtResult.Text = c.ToString();
        }

As in Example you can see that how we have created a dll and then how we used that dll into our project.
You can also see the articles How to use Crystal Report in C#.Net.

Opinions expressed by DZone contributors are their own.

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!