Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1303002
  • 博文数量: 482
  • 博客积分: 13297
  • 博客等级: 上将
  • 技术积分: 2890
  • 用 户 组: 普通用户
  • 注册时间: 2009-10-12 16:25
文章分类

全部博文(482)

文章存档

2012年(9)

2011年(407)

2010年(66)

分类: WINDOWS

2011-11-28 11:34:26

回复于: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;   }
      }
}

====

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