Implicit Conversion: Nullable(Of T) => T | VB.NET LINQ Query Syntax Vs Method Syntax -


the method syntax blocking implicit conversions, query syntax not. option strict on. how can force errors appear when using query syntax?

whole (completely runnable) program:

option strict on  module module1  sub main()      dim custlist new list(of cust)()     custlist.add(new cust() {.name = "mr. current", .deleted = false})     custlist.add(new cust() {.name = "mrs. deleted", .deleted = true})     custlist.add(new cust() {.name = "miss null", .deleted = nothing})      dim querysyntax =         c in custlist         c.deleted = false 'no error (the problem)      dim methodsyntax =         custlist _         .where(function(c) c.deleted = false) 'compiler error (desired effect)      each c cust in querysyntax         console.writeline("q: " & c.name & " " & c.deleted)     next      each c cust in methodsyntax         console.writeline("m: " & c.name & " " & c.deleted)     next      console.readkey(true)  end sub  class cust     public property name() string     public property deleted() system.nullable(of boolean) end class  end module 

lines crux of question:

where c.deleted = false 'no error .where(function(c) c.deleted = false) 'compiler error 

i'm going go out @ least bit of limb , offer i've found explanation behavior.

i took code , changed 'c.deleted = nothing' in querysyntax version , got "green squiggly" saying "this expression evaluate nothing due null propagation of equals operator." led me think how compiler interpreting expression, , did bit more snooping, , found following:

vb.net linq entities null comparison - 'is nothing' or '= nothing'?

from post, appears when nullable(of t) involved in expression, compiler internally promoting (or, suppose, more accurately, "lifting") equality operator nullable(of t) version, suppose not, technically, "implicit conversion." result, doesn't generate compile-time error. because element passed parameter function in methodsyntax version, lifting operator isn't being applied, , compiler traps implicit conversion syntax.


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -