C#编程:用Substring获取年份生肖-4

108 阅读1分钟

\

\

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为鸡年,以此类推。