Is there something similar to β€œc” in vb.net, but functions?

I use the same function over and over in a string, is there a way to just be like

with basicmove()
{(r),(u, 20),(r)
end with

instead

    basicmove(r)
    basicmove(u, 20)
    basicmove(r)

EDIT: Or

        basicmove(l, 5)
    basicmove(d, 3)
    basicmove(l, 21)
    basicmove(u, 5)
+4
source share
4 answers

I'm not quite sure that this applies to everything you ask for, but perhaps this will give you an idea.

EDIT: based on an updated question, I have another solution. This requires an understanding of two-dimensional arrays in programming. You simply load all the "coordinates" into the array, and then repeat them and perform the operations in the same order in which they are entered into the array.

Sub Main()
    ' multi-dimensional array of moves (there are plenty of way to create this object if this is confusing)
    Dim myList(,) As Object = New Object(,) { _
                                {"l", 5}, _
                                {"d", 3}, _
                                {"l", 21}, _
                                {"u", 5} _
                            }

    ' iterate the array and perform the moves.
    For x As Integer = 0 To myList.GetUpperBound(0)
        ' getting coordinates from the first & second dimension
        basicmove(myList(x, 0), myList(x, 1))
    Next

    Console.ReadLine()
End Sub

Private Sub basicmove(ByVal a As String, ByVal b As Integer)
    Console.WriteLine("param1:" & a & ",param2:" & b)
End Sub
+1
source

, . , List.ForEach For Each:

moves.ForEach(Function(r) basicmove(r))

List(Of Move).

+2

Sorry C # syntax. This has not been verified, so there may be errors.

public class myWith{
public List<Object> params{get;set;}
   public with(Action<Object> function){
      params.ForEach(p=>function(p));
   }     
}

Idea of ​​use:

new myWith(x=>doStuff(x)){
    params = new List<Object>{r, {u,20}, r}
}

We hope this idea gets through

0
source

This is not the most beautiful, although it works using implicit arrays:

Private Sub MakeCalls()
    Dim r As Integer = 1 : Dim u As Integer = 2
    For Each o In {({r}), ({u, 20}), ({r})}
        basicmove(o)
    Next
End Sub     
Private Sub basicmove(params() As Integer)
    For Each i As Integer In params
        Debug.Print(i.ToString)
    Next
End Sub
0
source

All Articles