How to do a single line If statement in VBScript for Classic-ASP?

后端 未结 5 1790
萌比男神i
萌比男神i 2020-12-14 06:41

The \"single line if statement\" exists in C# and VB.NET as in many other programming and script languages in the following format

lunchLocation = (dayOfTheW         


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-14 07:14

    There's a weird trick possible (hi, Python!) for exact one-liner:

    lunchLocation = array("Food Court", "Fuddruckers")(-(dayOfTheWeek = "Tuesday"))
    

    The "magic" works because of a boolean operation specifics in VBScript. True is actually -1 and False is 0, therefore we can use it as an index for array (just get rid of a minus). Then the first item of array will be a value for False condition and second item for True.

提交回复
热议问题