Chinaunix首页 | 论坛 | 博客
  • 博客访问: 28539
  • 博文数量: 25
  • 博客积分: 150
  • 博客等级: 入伍新兵
  • 技术积分: 160
  • 用 户 组: 普通用户
  • 注册时间: 2012-03-01 16:32
文章分类
文章存档

2012年(25)

我的朋友
最近访客

分类:

2012-03-01 17:09:57

回复于:2006-05-22 15:21:40
使用时想Value[i]如何写get和set方法?

====================================
使用索引器,

using   System;
class   IndexerClass  
{
      private   int   []   myArray   =   new   int[100];  
      public   int   this   [int   index]    
      {
            get  
            {
                  if   (index   <   0   ||   index   > =   100)
                        return   0;
                  else
                        return   myArray[index];
            }
            set  
            {
                  if   (!(index   <   0   ||   index   > =   100))
                        myArray[index]   =   value;
            }
      }
}

============================================================================================

#5楼 得分:10回复于:2003-04-17 15:08:48

puclic   class   A
{
      private   int   _b[][]   ;
      public   int       B[][]
      {
              set{   _b   =   value;   }
              get   {   return   _b;   }
      }
}

====

阅读(498) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~