下面这个程序中m,n不是没有被付值吗,怎么会有值?
using System;
namespace ConsoleApplication1{ /// <summary>
/// Class1 的摘要说明。
/// </summary>
///
///
///<summary>
/// 应用程序的主入口点。
/// </summary>
//[STAThread]
class a
{
protected internal int m;
public static int n;
public void display()
{
m++;
n++;
Console.WriteLine(m);
Console.WriteLine(n);
}
}
class Class1
{
static void Main(string[] args)
{
a a1=new a();
a1.display();
a a2=new a();
a2.display();
a a3= new a();
a3.display();
string s=Console.ReadLine();
Console.WriteLine(s);
Console.ReadLine();
//
// TODO: 在此处添加代码以启动应用程序
//
}
}
}
解决方案 »
- 高手来试试,菜鸟不要来-------GDI画图遮罩问题
- 急急急!!保存xml文件时,弹框“该文件已在源编辑器之外被修改是否重新加载它??”
- 很久以前写的五子棋程序
- ListViewItem.ListViewSubItem lvsi;是什么意思,ListViewItem.ListViewSubItem是属性还是类呢?
- string strCom = " SELECT * FROM [" + strTable + "$] ";
- 如何将splitContainer中的panel设置为上下放置的(在属性面板中设置,非代码实现)
- 关于数据库键表的问题,比较急!
- 求助!用C#实现邮件槽的问题,请大家帮忙(附代码)
- 郁闷~~试了好久都没法把纸的大小设好……
- 我该怎么改变字体呢?
- 有什么好办法分离字符串中的单个汉字 和 一个单词 和 标点符号
- 各位高手,谁能帮我解答关于数据库编程的问题
a3.display();
静态变量
{
m++;//是不是已经递加了。。
n++;
Console.WriteLine(m);
Console.WriteLine(n);
}
public void display()
{
m++;
n++;
Console.WriteLine(m);
Console.WriteLine(n);
}
你首先调用m++;所以,你的输出应该是从1开始!!!
namespace ConsoleApplication1{ /// <summary>
/// Class1 的摘要说明。
/// </summary>
///
///
///<summary>
/// 应用程序的主入口点。
/// </summary>
//[STAThread]
internal class a
{
protected internal double m;
public static int n;
internal void display()
{
m++;
n++;
Console.WriteLine(m);
Console.WriteLine(n);
}
}
internal class b: a
{
public void display1()
{
display();
Console.WriteLine("nihaoa ");
}
}
class Class1
{
static void Main(string[] args)
{
b a1=new b();
a1.display();
Console.WriteLine(a1.m);////////为什么可以直接访问m
a a2=new a();
a2.display();
string s=Console.ReadLine();
Console.WriteLine(s);
Console.ReadLine();
//
// TODO: 在此处添加代码以启动应用程序
//
}
}
}我在class a中已经把m设定为internal 了,那为什么在main中还可以直接访问,internal不是显示指定该类只有项目内部才嫩访问吗?
2.internal可以被本组合体(Assembly)内所有的类存取,组合体是C#语言中类被组合后的逻辑单位和物理单位,其编译后的文件扩展名往往是“.DLL”或“.EXE”。class a和class1是在一个组合体中.
internal
private
protect
public 所表示的意思
想知道更多,买本书吧!或者给多点分!
哈,我还要做星呢!