Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the VB.NET equivalent to this C# code?

VB.NET equivalent to this C# code?

    ctx.Load(site,
                x => x.Lists.Where(l => l.Title != null));

I've tried

 ctx.Load(site, Function(x) x.Lists.Where(Function(l) l.Title IsNot Nothing))

but this errors with "The expression (Convert(l.Title) != null) is not supported."

Thoughts

like image 688
Bob Avatar asked Oct 15 '22 08:10

Bob


2 Answers

if Title is string try use IsNullOrEmpty();

or

Nullable(Of T).HasValue if Title is Nullable

or

Sub Main()

        Dim list As New List(Of A)

        Dim a1 As New A
        a1.Title = "sqws"
        Dim a2 As New A
        a2.Title = Nothing


        list.Add(a1)
        list.Add(a2)

        Dim q = From c In list Where c.Title IsNot Nothing

    End Sub



    Public Class A

        Dim t As String

        Public Property Title() As String
            Get
                Title = t
            End Get
            Set(ByVal value As String)
                t = value
            End Set
        End Property

    End Class
like image 172
garik Avatar answered Oct 18 '22 15:10

garik


This may be cheating, but I have used Reflector in the past to decompile my C# code and then display it as other .NET languages just to see how they would look as I am most fluent in C#

like image 32
Rob Goodwin Avatar answered Oct 18 '22 13:10

Rob Goodwin