您的位置:首页 > 编程语言 > C#

C#_修饰符的学习:

2008-12-16 23:47 267 查看
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class xiushifu //用CLASS来创建一个类
{
public int a;//访问不受限制;
private int b;//私有的,只有包含此字段的类可以访问;
protected int c;//仅在当前类和派生类中可以访问;
internal int d;//仅在当前命名空间里可以访问;
int e;//没有修饰符,默认是私有的字段:
public int B//创建一个属性,记住和方法的不同之处是属性的签名后面没有括号,而方法是有括号的
{
get { return this.b; }
protected set { this.b = value; }//如果属性中没有SET,说明此属性是只读属性,
}

}
class xiushifu2 : xiushifu
{
public int x;
public int b()//创建一个方法,记住与属性的区别哟
{
base.B=123;
return base.B;

}

}
}
=============

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
xiushifu2 x = new xiushifu2();
Console.WriteLine(x.b());

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: