1using System;
 2
 3namespace test15
 4{
 5
 6    class Class1
 7    {
 8        /// <summary>
 9        /// 应用程序的主入口点。
10        /// </summary>

11        [STAThread]
12        static void Main(string[] args)
13        {
14            IntHelper myint = new IntHelper();
15            myint.Value = 123456;
16            try
17            {
18                Console.WriteLine(myint[0]);
19            }

20            catch(Exception e)
21            {
22                Console.WriteLine(e.Message);
23            }

24        }

25    }

26
27/// <summary>
28/// 对一个整数,通过从左至右给定一个序号(索引),得到第几位是多少
29/// </summary>

30    public class IntHelper
31    {
32        private int v;
33        public int Value  //定义属性
34        {
35            get{return v;}
36            set{this.v = value;}
37        }

38        public int this[int index]//定义索引
39        {
40            get
41            {
42                char[] mysplit = new char[10];
43                int m,i=0;
44                while(v>0)
45                {
46                    m = v%10;
47                    mysplit[i] = (char)m;
48                    i++;
49                    v = v/10;
50                }

51                if(index>=|| index<0throw new Exception("参数下标越界错误");
52                return mysplit[i-index-1];
53            }

54        }

55    }

56}

57

只有注册用户登录后才能发表评论。

posts - 46, comments - 16, trackbacks - 0, articles - 7

Copyright © 火山工作室