1.结构
//使用构造函数
SUM structA = new SUM(1,2);
//重新修改值
structA.x = 3;
structA.y = 4;
int Count = structA.DoSUM();

//定义一个结构体,包含构造函数和方法
struct SUM
{
public int x;
public int y;

public SUM(int x,int y)
{
this.x = x;
this.y = y;
}

public int DoSUM()
{
return this.x+this.y;
}
}结构和类的区别:结构的构造函数必须包含参数,而且不能有析构函数。除此之外,结构是隐式密封的(sealed)。
2.数组声明后在使用前需要实例化,如:
输出结果:
ABC
def
defg
3.数组中使用foreach,如:
string strName = String.Empty;
foreach(ListItem item in this.WFUserNameListBox1.Items)
{
if (item.Selected==true)
{
strName += item.Value;
}
}
//使用构造函数
SUM structA = new SUM(1,2);
//重新修改值
structA.x = 3;
structA.y = 4;
int Count = structA.DoSUM();
//定义一个结构体,包含构造函数和方法
struct SUM
{
public int x;
public int y;
public SUM(int x,int y)
{
this.x = x;
this.y = y;
}
public int DoSUM()
{
return this.x+this.y;
}
}2.数组声明后在使用前需要实例化,如:
//声明并实例化数组
//Method 1
string[] strArray1 = new string[2];
strArray1[0]="ABC";
Response.Write(strArray1[0] + "<BR>");
//Method 2
string[] strArray2 = new string[] {"abc","def"};
Response.Write(strArray2[1] + "<BR>");
//Method 3
string[] strArray3 = "abc,defg".Split(',');
Response.Write(strArray3[1] + "<BR>");
//Method 1
string[] strArray1 = new string[2];
strArray1[0]="ABC";
Response.Write(strArray1[0] + "<BR>");
//Method 2
string[] strArray2 = new string[] {"abc","def"};
Response.Write(strArray2[1] + "<BR>");
//Method 3
string[] strArray3 = "abc,defg".Split(',');
Response.Write(strArray3[1] + "<BR>");
ABC
def
defg
3.数组中使用foreach,如:
string strName = String.Empty;
foreach(ListItem item in this.WFUserNameListBox1.Items)
{
if (item.Selected==true)
{
strName += item.Value;
}
}

浙公网安备 33010602011771号