Highlighted
Absent Member.
Absent Member.
1600 views

Lambda expression and Linq

Jump to solution

Hi!
In this new version of VC, it's possible to use linq or lambda expressions, like, "myList.ForEach(x => Console.WriteLine(x));" ?

Tags (3)
0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Lambda expression and Linq

Jump to solution

This should work, but I think the delegate for the Where method needs to return a boolean (condition-value in COBOL), so something like this:

     $set ilusing"System.Collections.Generic"

     $set ilref"System.Core"

      01 myList type List[string].

      01 myList2 type IEnumerable[string].

          invoke myList::ForEach(

              delegate (x as string)

                  display x

              end-delegate)

          set myList2 to myList::Where(delegate using x as string returning y as condition-value

                                                      set y to false

                                                      if(x::Length > 1)

                                                          set y to true

                                                      end-if

                                                  end-delegate).

The reference to System.Core is required since Where is actually an extension method defined in that assembly.  Normally it would be better to set this ilref directive, and the ilusing directive using project settings In Visual Studio.

View solution in original post

0 Likes
2 Replies
Highlighted
Absent Member.
Absent Member.

RE: Lambda expression and Linq

Jump to solution

About use the "ForEach" of list class, I solved...

           invoke myList::ForEach(delegate using x as type String
                                           invoke type Console::WriteLine(x)
                                      end-delegate).

but, it's possible to use the Linq to objects method ?

Something like this ??????:
set minhaNovaLista to minhaLista::Where(delegate using x as type String returning y as type String
                                                       if(x::Length > 1)
                                                           move x to y
                                                       end-if
                                                   end-delegate).

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Lambda expression and Linq

Jump to solution

This should work, but I think the delegate for the Where method needs to return a boolean (condition-value in COBOL), so something like this:

     $set ilusing"System.Collections.Generic"

     $set ilref"System.Core"

      01 myList type List[string].

      01 myList2 type IEnumerable[string].

          invoke myList::ForEach(

              delegate (x as string)

                  display x

              end-delegate)

          set myList2 to myList::Where(delegate using x as string returning y as condition-value

                                                      set y to false

                                                      if(x::Length > 1)

                                                          set y to true

                                                      end-if

                                                  end-delegate).

The reference to System.Core is required since Where is actually an extension method defined in that assembly.  Normally it would be better to set this ilref directive, and the ilusing directive using project settings In Visual Studio.

View solution in original post

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.