Bob
Bob

Reputation: 81

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

Upvotes: 5

Views: 381

Answers (4)

Rob Goodwin
Rob Goodwin

Reputation: 2767

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#

Upvotes: 2

Aaron Daniels
Aaron Daniels

Reputation: 9664

Have you tried the IsNothing function?

ctx.Load(site, Function(x) x.Lists.Where(Function(l) Not IsNothing(l.Title)))

EDIT:

Now that you've specified that Title is a String, then you should use the IsNullOrEmpty function.

ctx.Load(site, Function(x) x.Lists.Where(Function(l) Not String.IsNullOrEmpty(l.Title)))

Upvotes: 0

garik
garik

Reputation: 5746

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

Upvotes: 2

Patrick Karcher
Patrick Karcher

Reputation: 23603

This really should work:

ctx.Load(site, Function(x) x.Lists.Where(Function(l) l.Title.IsNullOrEmpty = False))

If it does not, let me know the error message.

Upvotes: 0

Related Questions