I have a DLL which I have included in my C# project. Let’s call it “one.dll”
This DLL contain a static class named “staticclass”
I have another DLL which I have also included in same project. Let’s call it “two.dll”
This DLL also contain a static class named “staticclass”
Now when I include both DLLs at the same time in my project and try to access “staticclass” then naturally it gives error. Is there a way I can change the name of class or give it some kind of alias so let’s say “staticclass” in “one.dll” will remain as it is, and I can give alias to “staticclassTwo” which is in “two.dll”
Please note I do not have access to source codec of both “one.dll” and “two.dll”
(I’m assuming the two classes are also in the same namespace. If they’re not, it’s easy – just use simple
usingdirectives for aliases, or the fully qualified name in the code.)You can indeed give an alias – an extern alias. Effectively this adds “assembly” as another level of namespace differentiation.
Obviously you should avoid this situation when you can, but it’s nice that C# provides a way of being very explicit when you absolutely have to.
Anson Horton has a good walkthrough for how you use them in practice.