天天看點

C#程式設計:用Substring擷取年份生肖

private void button4_Click(object sender, EventArgs e)

       {

           string TreeYear = "猴雞狗豬鼠牛虎兔龍蛇馬羊";

           int i = 2017;

           int j = i % 12;

           MessageBox.Show(j+ " " + TreeYear.Substring(j,1));

       }

小結:

年份除以12取餘,0為猴年,1為雞年,以此類推。