可访问性错误不一致

时间:2015-03-28 16:00:46

标签: c#

我目前正在编写一个程序并遇到了2个错误,我认为这些错误是相关的,我不确定如何解决。读错了......

1)

  

错误1可访问性不一致:参数类型' ref ProgrammingAssignment2.AVLTree'比方法' ProgrammingAssignment2.EditCountryForm.EditCountryForm(ref ProgrammingAssignment2.AVLTree,Sy​​stem.Windows.Forms.DataGridView)' C:\ Users \ Adam \ documents \ visual studio 2010 \ Projects \ ProgrammingAssignment2 \ ProgrammingAssignment2 \ EditCountryForm.cs 17 16 ProgrammingAssignment2

2)

  

错误2可访问性不一致:属性类型' ProgrammingAssignment2.AVLTree'比财产更容易获得' ProgrammingAssignment2.EditCountryForm.stuffs' C:\ Users \ Adam \ documents \ visual studio 2010 \ Projects \ ProgrammingAssignment2 \ ProgrammingAssignment2 \ EditCountryForm.cs 60 33 ProgrammingAssignment2

编辑表格中的错误如下......

public partial class EditCountryForm : Form
{

public Country ToEdit;

public EditCountryForm(ref AVLTree<Country> newTree,DataGridView newDataGridView)
{
    this.data = newDataGridView;
    this.thing = newTree;
    InitializeComponent();
}

和...

public AVLTree<Country> thing { get {return thing;} 
        set{this.thing = value;}

我的AVLTree课程是......

public class AVLTree<T> : BSTree<T> where T : IComparable
{
    public new void InsertItem(T item)
    {
        insertItem(item, ref root);
    }

    public void insertItem(T item, ref Node<T> tree)
    {
        if (tree == null)
        {
            tree = new Node<T>(item);
        }

        else if (item.CompareTo(tree.Data) < 0)
        {
            insertItem(item, ref tree.Left);
        }

        else if (item.CompareTo(tree.Data) > 0)
        {
            insertItem(item, ref tree.Right);
        }

        tree.BalanceFactor = height(tree.Left) - height(tree.Right);

        if (tree.BalanceFactor <= -2)
        {
            rotateLeft(ref tree);
        }
        if (tree.BalanceFactor >= 2)
        {
            rotateRight(ref tree);
        }
    }



    //Rotate the tree to the left
    public void rotateLeft(ref Node<T> tree)
    {
        Node<T> newRoot;
        //Check the Balance factor of tree.Right before rotation

        if (tree.Right.BalanceFactor > 0)
        {
            //Recursive call on the rotateRight method

            rotateRight(ref tree.Right);
        }
        //Put newRoot to tree.Right
        newRoot = tree.Right;
        //Put tree.Right equal to newRoot.Left
        tree.Right = newRoot.Left;
        //make newRoot.Left equal to tree
        newRoot.Left = tree;
        //make tree equal the newRoot
        tree = newRoot;
    }


    public void rotateRight(ref Node<T> tree)
    {
        Node<T> newRoot;
        //check the Balance factor of tree.Right before double rotation
        if (tree.Left.BalanceFactor < 0)
        {
            //make recursive call on the rotateRight method
            rotateLeft(ref tree.Right);
        }
        //assign newRoot to tree.Right
        newRoot = tree.Left;
        //make tree.Right equal to newRoot.Left
        tree.Right = newRoot.Right;
        //make newRoot.Left equal to tree
        newRoot.Right = tree;
        //make tree equal the newRoot
        tree = newRoot;
    }


    public Country ReturnCountryInfo(Country FindRow)
    {
        Country SelectedCountry = new Country(FindRow.Name, FindRow.GdpGrowth, FindRow.Inflation, FindRow.TradeBalance, FindRow.HdiRankings, FindRow.TradePartners);
        return SelectedCountry;
    }


}

}

我的国家班级是......

 public class Country : IComparable
{
    // Country Properties

    public String name;
    public float gdpGrowth;
    public float inflation;
    public float tradeBalance;
    public float hdiRanking;
    public LinkedList<String> tradePartners;




    //Constructor

    public Country(String name, float gdpGrowth, float inflation, float tradeBalance, float hdiRanking, LinkedList<String> tradePartners)
    {
        this.name = name;
        this.gdpGrowth = gdpGrowth;
        this.inflation = inflation;
        this.tradeBalance = tradeBalance;
        this.hdiRanking = hdiRanking;
        this.tradePartners = tradePartners;
    }

    public String Name
    {
        set { this.name = value; }
        get { return name; }
    }

    public float GdpGrowth
    {
        set { this.gdpGrowth = value; }
        get { return gdpGrowth; }
    }

    public float Inflation
    {
        set { this.inflation = value; }
        get { return inflation; }
    }

    public float TradeBalance
    {
        set { this.tradeBalance = value; }
        get { return tradeBalance; }
    }

    public float HdiRankings
    {
        set { this.hdiRanking = value; }
        get { return hdiRanking; }
    }

    public LinkedList<String> TradePartners
    {
        set { this.tradePartners = value; }
        get { return tradePartners; }
    }

    public override string ToString()
    {
        return name + ", " + gdpGrowth + ", " + inflation + ", " + tradeBalance + ", " + hdiRanking + ", " + tradePartners;
    }

    public int CompareTo(object other)
    {

           // Country temp = (Country)other;
            //return name.CompareTo(temp.name);
           // throw new StackOverflowException();
        return 1;

    }


}

}

如果有人能帮我解决这个问题,那就太棒了,谢谢

1 个答案:

答案 0 :(得分:1)

简单地说,您的代码不是您编译的代码:

要么:

public class AVLTree<T>

或者这个:

public class Country

不是您的编译器编译的。仔细检查它们是否公开,然后重新编译。

顺便说一下:

public AVLTree<Country> thing { get { return thing; } set{this.thing = value;}

这是完全错误的,也不应该编译。您已经构建了一个无限递归,将在运行时生成StackOverflow。但是你的编译器应该足够聪明才能注意到。

有些东西没了。您的代码和编译错误不匹配。