十二、流程控制之条件运算符
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespace_12.流程控制之条件运算符{classProgram{staticvoidMain(string[]args){/***三元运算符也称条件运算符**其语法:*<test>?<resultTrue>:<resultFalse>**其执行过程如下:*计算表达式<test>的值,如果为true,则执行resultTrue表达式,否则执行resultFalse表达式。**执行条件运算符会得到一个返回结果。**///使用条件运算符求出三个整数中的最大值。intmax,a=6,b=5,c=7;max=(a>b)?a:b;max=(max>c)?max:c;Console.WriteLine("a={0},b={1},c={2}三个整数中的最大值为:{3}",a,b,c,max);Console.ReadKey();}}}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。