using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;namespace changzhen
{//显示所有图片的树状图,继承了TreeView,Observer两个类
    public class List : TreeView, Observer
    {
          private Model model; //构造函数
public List()
{
} //实现自己的dataUpdate
public void dataUpdate(Model model,string str,int npara)
{
this.model = model;
//如果操作为删除、添加和更新属性则重画树状图
if(str.Equals("3") || str.Equals("4") || str.Equals("5"))
DrawTree();
//如果是添加操作,还要负责将结点设为打开状态
if(str.Equals("4"))
this.Nodes[npara].Expand();
}

//设置视图对应的模型
public void SetModel(Model model)
{
this.model = model;
DrawTree();
}

//创建一个结点(表示照片的一个种类),参数是
private void InsertAlbum(string strName, int nAlbum)
{
TreeNode node = new TreeNode(strName);
node.Tag = new TreeItem(ItemType.Album, nAlbum);
 
//向树状图中插入一个子结点
this.Nodes.Add(node);
} //插入照片,需要指定的参数是照片种类、照片名称、照片本身
private void InsertPhoto(int nAlbum, string strName, int nPhoto)
{
TreeNode node = new TreeNode(strName);
node.Tag = new TreeItem(ItemType.Photo, nPhoto);

//向nAlbum结点中插入一个子结点
this.Nodes[nAlbum].Nodes.Add(node); } //每次执行完删除、添加和更新属性操作都会调用
private void DrawTree()
{
ArrayList textlist=new ArrayList();

//将当前展开的结点放入textlist中
for(int i=0;i<this.Nodes.Count;i++)
{
if(this.Nodes[i].IsExpanded)
textlist.Add(this.Nodes[i].Text);
} //把原视图清空(Nodes是TreeNode的一个成员)
this.Nodes.Clear(); //将结点加入TreeNode中
for(int i=0;i<model.albumList.Count;i++)
{
InsertAlbum((string)model.albumList[i], i);
} //将子结点加入TreeNode中
for(int i=0;i<model.idList.Count;i++)
{
InsertPhoto((int)model.categoryList[i], (string)model.nameList[i], (int)model.idList[i]);
} //把原来做过标记(已经打开)的结点打开
for(int i=0;i<this.Nodes.Count;i++)
{
if(textlist.Contains(this.Nodes[i].Text))
this.Nodes[i].Expand();
} }

}
}
编译错误:错误 1 可访问性不一致: 参数类型“changzhen.Model”比方法“changzhen.List.dataUpdate(changzhen.Model, string, int)”的可访问性低 C:\Documents and Settings\yangpan1\My Documents\Visual Studio 2005\Projects\changzhen\changzhen\list.cs 18 15 changzhen

解决方案 »

  1.   

    当定义一个返回参数的方法的时候,如果返回参数的访问级别低于方法的访问级别就会出现这样的错误,从OO来说,这个是可以理解的,如果返回的参数不能被访问,那么定义的返回的方法也是错误的.那么定义返参方法的时候,返回参数可访问级别一定要大于或等于方法的可访问级别. protected User getUserById(int userId)
    {
      User u =null;
      //some create user 
      return u;
    }private class User
    {
      private int _userId ;
      public User(int userId)
      {
        _userId = userId;
      }
    }如果以上代码,这个是不能被编译器编译通过的, 其原因就在于返参的可访问性低于了返参方法的可访问性.
    protected private public 的访问性不一样的.