Re: I don't like this behavior - implicitly returning value types

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



On Jan 30, 2:02 pm, "rowe_newsgroups" <rowe_em...@xxxxxxxxx> wrote:
I just noticed this about value types and return values, and it kind
of bugs me that the compiler won't treat it as an error, even with
Option Strict On.

Try this out:

Option Strict On

Public Class MyClass

Private Sub ExtractionSettings_Load(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MsgBox(MyProp.ToString())
End Sub

ReadOnly Property MyProp() As Int16
Get

End Get
End Property

End Class

This will compile and run perfectly fine (if I typed it right :-) ),
always showing 0 in the opening messagebox. I really wish that the IDE
would tell me that I didn't explicitly specify a return value for
MyProp. (Yes, I know it's a value type and therefore it has a value of
0 at instantiation so it is returning a value, and thus not violating
the return value rules).

Is there a setting I missed somewhere that I could use to flag this as
an error?

Thanks,

Seth Rowe

Seth,

I wonder if it's like that to keep as much compatibility with VB6 as
possible. Though, you'd think a warning would be an acceptable
compromise.

Brian


.



Relevant Pages

  • Re: I dont like this behavior - implicitly returning value types
    ... of bugs me that the compiler won't treat it as an error, ... Option Strict On. ... Public Class MyClass ... from functions/properties via assigning to the function name - if you ...
    (microsoft.public.dotnet.languages.vb)
  • Re: I dont like this behavior - implicitly returning value types
    ... of bugs me that the compiler won't treat it as an error, ... Option Strict On. ... Public Class MyClass ... ReadOnly Property MyProp() As Int16 ...
    (microsoft.public.dotnet.languages.vb)
  • I dont like this behavior - implicitly returning value types
    ... of bugs me that the compiler won't treat it as an error, ... Option Strict On. ... Public Class MyClass ... ReadOnly Property MyProp() As Int16 ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Wish I was using .net
    ... With "Option Strict On", the VB 2005 compiler won't allow your code. ... gives the warning "Option Strict On disallows implicit conversions from ... dim dblRate as double, dblHours as double ...
    (microsoft.public.vb.general.discussion)
  • Re: VB vs. C# language challenge question
    ... Once you turn on Option Strict and Option Explicit, ... assumptions about the code and forces cleaner code. ... so having the compiler report an error is actually better ...
    (microsoft.public.dotnet.framework)