Which is more efficient, writing a class or adding a reference to dll created for the class?
This is a general question. One of my colleague was using a class I wrote and he wanted to use a dll开发者_运维问答 created for the class rather than adding the class to his solution because of some efficiency problem. Is it always better to use a dll rather than writing a class?
Thanks.
Not sure I understand your question, but it sounds like you're asking whether you should share source code or share the copiled code.
Copying source code is rarely a good idea if you're really trying to reuse the code (rather than using it as a jump-off point for something else). Over time, separate copies can change in their own ways, and thus multiplying the effort it would take to maintain the code.
If you share the compiled library, it can be maintained on its own and fixes/changes distributed to consumers.
It's better to only have the source code in one place, and reuse it, generally. This isn't for efficiency reasons - it's to have one place to fix bugs, add features etc.
It's best to have the source in one place. If you want to use the same file in another project I'd advice you to link to the file instead.
Do this by choosing add existing file and then choose link instead of add in the dialog (click the triangle in the bottom right corner).
Add a reference to the C# project that contains the class you want to use. Even if you get a whole bunch of other classes that you won't use, it allows the changes to the class that you do need to be made in the referenced project, which makes it easier to maintain, as Jon mentioned.
精彩评论