码迷,mamicode.com
首页 > 其他好文 > 详细

静态类

时间:2015-09-09 11:22:59      阅读:116      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!