三元運算符寫法
using System;
using System.Collections.Generic;
using System.Text;
namespace projGetMaxScore
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? string[] name = {"吳松","錢東宇","伏晨","陳陸","周芯","林日鵬","何昆","關(guān)欣"};
? ? ? ? ? ? int[] score = {89,90,98,56,60,91,93,85};
? ? ? ? ? ? int temp = -1;
? ? ? ? ? ? int num = 0;
? ? ? ? ? ? for (int i = 0; i < score.Length; i++) {
? ? ? ? ? ? ? ? temp = score[i] > temp ? score[i] : temp;
? ? ? ? ? ? ? ? num = temp == score[i] ? i : num;
? ? ? ? ? ? }
? ? ? ? ? ? Console.Write("分數(shù)最高的是{0},分數(shù)是{1}",name[num],score[num]);
? ? ? ? }
? ? }
}
2020-11-04
感興趣可以康康,我沒啥問題