Why no error in VB.NET
vb.net
Solution
Double click your Project -> My Project.
Goto Compile and look for Warningconfiguration
Now you can change some settings.
- Implicit cast
- Late Binding
don't make them errors but warnings.
That won't make compile time errors but you can at least see some warnings.
Another solution would be to make your class a partial class and move your code to a new file. You can set Option Strict / Option Explicit on a per file basis.
Problem
I have recently switched from a c# team to a vb.net team. One of the things I have not been able to find an answer to is the differences in compile error / options. Let me explain. In C# i will, using default settings, get a compile time error when trying to pass in an invalid type to a templated class like below. Here I create an Animal with a string type and afterwards I pass in a datetime which results in an compile error. ``` IAnimal<string> animal = new Animal<string>(); animal.SetTrainer(DateTime.Now); ``` I know I will get the same compile time error in vb.net with "Option Strict". There is, however, a lot of legacy (VB) code in the same file that will not compile with "Option Strict". What options do I have. Im thinking this: - Switch to "Option Strict" and fix all errors. Will take some time and may break working code. - Maybe there is an alternate that will ensure compile time check of generics. After all generics are rather new so maybe there is a way of always enforcing this. - ? Thanks in advance