Пример #1
0
        public static void Run()
        {
            var methodName = new StackTrace().GetFrame(1).GetMethod().Name;

            Console.WriteLine(methodName);
            int    a  = 10;
            int    b  = 20;
            var    c  = 30;
            var    d  = Fun(a, b);
            string s1 = "10";
            string s2 = "20";
            var    s3 = "30";
            var    s4 = s3;

            Console.WriteLine("a is " + a);
            Console.WriteLine("c is " + c);
            Console.WriteLine("a+b=" + (a + b));
            Console.WriteLine("Fun(a,b) is " + d);
            Console.WriteLine("s1 is " + s1);
            Console.WriteLine("s1 + s2 is " + s1 + s2);
            Console.WriteLine("s3 + s4 is " + s3 + s4);
            Fun1();
            Console.WriteLine("a is " + a);
            ClSA cl = new ClSA()
            {
                Name = "012345", Address = "Ads0123", Number = 123
            };
            var t = ((IFormattable)cl).ToString("", new CustomFormatter());

            Console.Write("___");
            Console.Write(t);
            Console.Write("___");
            Console.ReadLine();
        }
Пример #2
0
        string ICustomFormatter.Format(string format, object arg, IFormatProvider formatProvider)
        {
            ClSA c = arg as ClSA;

            if (c != null)
            {
                return(string.Format("{0,-10:D9},{1,10},{2,10:x}", c.Name, c.Address, c.Number));
            }
            return(arg.ToString());
        }