Sunny's Technology Blog

书山有路勤为径,学海无涯苦作舟

博客园 首页 新随笔 联系 订阅 管理
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.数组声明后在使用前需要实例化,如:
            //声明并实例化数组
            
//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;
                }

            }
posted on 2005-08-15 11:01  Sunny  阅读(1292)  评论(0)    收藏  举报