首页 > 其他 > 详细

静态类

时间:2015-09-09 11:20:59      阅读:281      评论:0      收藏:0      [点我收藏+]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//静态类用static标记
//静态类的成员必须都是静态的
//静态类是密封的,不可继承
namespace StaticClass
{
    public static class MyMath
    {
        public static float PI = 3.14f;
        public static bool IsOdd(int x)
        {
            return x % 2 == 1;
        }
        public static int Times2(int x)
        {
            return 2*x;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            int val = 3;
            Console.WriteLine("{0} is Odd is {1}.",val,MyMath.IsOdd(val));
            Console.WriteLine("{0}* 2={1}.", val, MyMath.Times2(val));
        }
    }
}

静态类

原文:http://www.cnblogs.com/sulong/p/4793851.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!