dotnet / dotnet/vblang

Ternary Select Case

Open
#342 12 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

I suggest this syntax for a Ternary Select Case:

```
Dim Result = Select Case I
Case 0: "Zero"
Case 1: "One"
Case 10: "Ten"
Case 100: "Hundred"
Case 1000: "Thouzand"
Case Else: "Any Other Number"
End Select
```

This is a short syntax for:
```
Dim Result As String
Select Case I
Case 0
Result = "Zero"
Case 1
Result = "One"
Case 10
Result = "Ten"
Case 100
Result = "Hundred"
Case 1000
Result = "Thouzand"
Case Else
Result = "Any Other Number"
End Select
```

It is doable today like this:
```
Dim timeOfWeek = (Fumction(x)
Select Case X
Case 0: return "Zero"
Case 1: return "One"
Case 10: return "Ten"
Case 100: return "Hundred"
Case 1000: return "Thouzand"
Case Else: return "Any Other Number"
End Select
End Function) (I)
```
But it will be nice to simplify this syntax.. I suggest:

```
Dim timeOfWeek = Evaluate(x = I) As string
Select Case X
Case 0: return "Zero"
Case 1: return "One"
Case 10: return "Ten"
Case 100: return "Hundred"
Case 1000: return "Thouzand"
Case Else: return "Any Other Number"
End Select
End Evaluate
```
The Evaluate block is a lamda expression with suplied values for its parameters. this aloow us to evaluate any expression not just Select case, and work on any number of variables in the expresion.

If the Evaluate end Evaluate is not accepted, it can be done by the Function end function keywords, say like this:
```
Dim timeOfWeek = Function(x Integer:= I) As string
Select Case X
Case 0: return "Zero"
Case 1: return "One"
Case 10: return "Ten"
Case 100: return "Hundred"
Case 1000: return "Thouzand"
Case Else: return "Any Other Number"
End Select
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.