0

I have a couple of functions which I would like to add to DLL. I found this programming guide How to: Create and Use C# DLLs (C# Programming Guide). It's very short and looks like a really simple thing to do but I've noticed that each single function added to dll is enlosed in a separate file, separate class and functions are static. Is it always the case? What if I have a couple of overloaded functions, such as:

public void WaitForTheKey(object o = null) {} public void WaitForTheKey(string message, bool addlines = true, int[] quantity = null) {} private void _WaitForTheKey(string, bool, int[]) {} 

Shall I put them in separate files like in the tutorial? Thanks.


EDIT. If projects for DLL do not require separate classes and files, what would be the reason an author of the tutorial followed this theme?

Thanks

2 Answers 2

1

First of all you should keep you logic split by functionality. So all these methods you should keep in one class (in most cases it means one file).

It is very simple to create dll. If you use Visual Studio you should pick Class Library project type and then simply build it. As a result you will get dll file. Or use compiler directly from command prompt like it was shown in tutorial.

Sign up to request clarification or add additional context in comments.

2 Comments

What would be the reason for separating each function in different classes?. From what you have said, I don't have to follow the theme in the tutorial. But the reason for my question is that author of this tutorial did put each individual function into separate classes while Add and Multiply represent the same logic. I though this is what one needs to do to build a proper DLL file. Your answer doesn't clarify the problem.
I wasn't clear enough - you should keep these methods in once class. There is no point to separate them.
1

You are overthinking it; the tutorial is just an arbitrary example.

Simply structure the code in a way that makes sense, with as many or few classes as you like. Everything that is public in your assembly (classes, methods, properties, fields, events etc.) can be accessed by the consumer of the DLL.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.