The following forum(s) are migrating to a new home on Microsoft Q&A (Preview): Developing Universal Windows apps!

Ask new questions on Microsoft Q&A (Preview).
Interact with existing posts until December 13, 2019, after which content will be closed to all new and existing posts.

Learn More

 none
[CS]Method Name Expected while using Linq with Lambda Expression RRS feed

  • Question

  • I am partially new to C# (I have done basics with it, but most of my experience is with VB.NET), and am working on converting my VB.NET code to C# (I am converting my UWP apps to Xamarin, and all my UWP codebehind was written using VB.NET). I am trying to convert the following VB.NET to C#:
    Imports Xamarin.Forms
    Public Class Class1
    	Public Sub Testing()
    		Dim fl As New FlexLayout()
    		Dim tempbtn As View
    		tempbtn = fl.Children.Where(Function(btn) btn Is GetType(Grid))(0)
    	End Sub
    End Class
    I thought that this would be similar to the following:
    tempbtn = fl.Children.Where(btn => btn.GetType() == typeof(Grid))(0);
    However, Visual Studio 2019 is giving me the message "Method Name Expected". What am I doing wrong? Thanks.

    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Monday, October 21, 2019 12:30 AM

All replies

  • Hi,

    You will need to change the (0) to FirstOrDefault() in C#.

    Like this:

    tempbtn = fl.Children.Where(btn => btn.GetType() == typeof(Grid)).FirstOrDefault();

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, October 21, 2019 6:18 AM
    Moderator