标题:初学者 求教。。。。
取消只看楼主
我是好学生
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-3-15
 问题点数:0 回复次数:0 
初学者 求教。。。。

using System;
namespace aaa
{
class n1
{
public static readonly uint max;
public static uint instance=0;

static n1()//静态构造方法
{
max=20;
}

public n1()//非静态的构造方法
{
instance++;

if(instance>max)
{
Console.WriteLine("too many instance");
}
}

public static void Main()
{
for(int i=0; i<21;i++)
{
n1 aa=new n1();
}
}
}
}

我这个程序在开始的时候 定义instance 这个属性为static 的 为什么非静态的构造方法可以访问它呢??我是刚学c#的 以前只学过c 希望那位高人 帮忙说得详细些。。。。好让我看得明白

搜索更多相关主题的帖子: public 
2007-03-16 17:35



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-124662-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.438320 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved