首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

实例化的参数是字符串加上标值,为什么定义的构造方法里的参数只有一个STRING S

2012-10-06 
实例化的参数是字符串加下标值,为什么定义的构造方法里的参数只有一个STRING S?public class bigdocument{

实例化的参数是字符串加下标值,为什么定义的构造方法里的参数只有一个STRING S?
public class bigdocument
{
public bigdocument(string s)
{
console.writeline("creating document with: {0}",s);
}
}


public class tester
{
static void main()
{
document[] folder=new document[5];
for(int i=0;i<5;i++)
folder[i]=new bigdocument("big document #"+i);
}
---------------------------------
这个S在原来的类里没有先定义,为什么在构造方法里就可以用呢?还有构造方法里面的占位符就一个,为什么实例化的时候可以有两参数new bigdocument(一个是这个"big document #"字符串+一个是这个下标值i);一个字符串加一个整形i。还有一个问题就是定义对象数组时为什么不用派生类bigdocument而用他的父类document呢?

}

[解决办法]
("big document #"+i);
这是一个参数,谢谢,楼主请先理清基础知识
[解决办法]

C# code
public bigdocument(string s){console.writeline("creating document with: {0}",s);} 

热点排行