The compiler in Visual Studio has more features than the compiler in Unity which means that some code (especially newer c# features) will give an error in Unity, but not in Visual Studio.
You can however change your target framework to match the one that is closest to what Unity uses in your editor. I have done this in Xamarin when developing libraries for Unity, but it looks like it is possible in Visual Studio as well.
In Visual Studio, in the DLL project's properties, set the Target framework property to the Unity framework version you're using. This is the Unity Base Class Library that matches the API compatibility that your project targets, such as the Unity full, micro, or web base class libraries. This prevents your DLL from calling framework methods that exist in other frameworks or compatibility levels, but which might not exist in the Unity framework version you're using.