2006/May/11

short-hand condition
อยากจะเขียนคำสั่งที่มีเงื่อนไขที่สั้นๆแต่ได้ผลเหมือนกับการเขียนคำสั่งยาวๆ ในแต่ละภาษานี้มีไม่เหมือนกันวันนี้เลยมาเขียนเก็บไว้
ในphpกับc#

(condition)?(true part):(false part);

Example

<?php
($x=$y)?$x=5:$x=0
;
//Equavalent
if($x=$y
)
$x=5
;
else
$x=0
;
?>

ในvb.Net

iif(condition,true part,false part)

Example

IIf(x = y, x = 5, x = 0)
'Equavalent
If x = y
Then
x = 5
Else
x = 0
End If

ชื่อ: 
เว็บไซต์: 
คอมเมนต์:




smilebig smileopen-mounthed smileconfused smilesad smileangry smiletonguequestionembarrassedsurprised smilewinkdouble winkcry
Python 2.5 ก็จะ if แบบนี้กะเค้าละ
#1  by  veer At 2006-05-11 15:20, 
งืมๆ ไม่ค่อยถนัดแบบย่อเลยแฮะ
#2  by  ฟิวส์ At 2006-05-12 10:29, 

<< Home