dotnet / dotnet/vblang

[Proposal] Improvements on the VisualBasic anonymous variable more elegant

Open
#437 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
328
Forks
71
PR merge metrics
No merged PRs in 30d

Description

Hi,

Currently the VisualBasic ``With`` anonymous variable syntax can save our coding time, but we just can not get the value of the **anonymous variable**, so I think we can using ``$`` to reference the anonymous variable and get its value:

```vbnet
Sub Main()
Dim array%() = {1, 2, 3, 5}

For i% = 0 To array.Length - 1
With array(i)
Call Console.WriteLine(.ToString)
Call Console.WriteLine($)
End With
Next

With PopulateData()
Call Console.WriteLine(.ToString)
Call Console.WriteLine($)
End With
End Sub

Public Function PopulateData() As Integer
Return 1
End Function
```

If this new feature was implented, then we can using this ``With`` anonymous variable syntax in a more elegant way:

```vbnet
Sub Main()
Dim array%() = {1, 2, 3, 5}

For i% = 0 To array.Length - 1
With array(i)

' using anonymous variable that we can know that
' this code block is focus on implement the function 1
Call Console.WriteLine(.ToString)
Call Console.WriteLine($)

' This $ reference to the anonymous variable of With array(i)
With PopulateData($)

' using anonymous variable that we can know that
' this code block is focus on implement the function 2
Call Console.WriteLine(.ToString)
' This $ reference to the anonymous variable of With PopulateData($)
Call Console.WriteLine($)
End With

' This $ reference to the anonymous variable of With array(i)
Call Console.WriteLine($ + 100)
End With
Next
End Sub

Public Function PopulateData(x%) As Integer
Return x% + 98%
End Function
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.