【问题标题】:Inconsistent Accessibility C#不一致的可访问性 C#
【发布时间】:2015-08-11 16:09:04
【问题描述】:

我正在开发用于跟踪股票的自定义 UI,尽管我制作的一个 UI 引起了我无法找到的问题。我不断收到错误消息:“不一致的可访问性:参数类型 'SCM_Addin.Funds.TrackFund[]' 比方法 'SCM_Addin.Forms.frm_FundTracker.frm_FundTracker(SM_Addin.Funds.TrackFund[])' 更难访问”

我检查了我的类中的保护,但我找不到任何会阻碍我的代码可访问性的私有变量。代码如下:

frm_FundTracker:

namespace SCM_Addin.Forms

{ 公共部分类 frm_FundTracker :表格 {

    public frm_FundTracker()
    {
        InitializeComponent();
    }

    public frm_FundTracker(String[] fundsToAdd, Double[] ePrices, Double[] cPrices)
    {

        InitializeComponent();

        int index = 0;
        foreach (String fund in fundsToAdd)
        {

            ListViewItem newFundItem = new ListViewItem(fund);
            newFundItem.SubItems.Add(ePrices[index].ToString());
            newFundItem.SubItems.Add(cPrices[index].ToString());

            this.list_Tracker.Items.Add(newFundItem);

            index++;

        }//END LOADING COLUMNS


    }//END FRM_FUNDTRACKER WITH ARRAYS

    public frm_FundTracker(TrackFund[] funds)
    {
        InitializeComponent();

        foreach (TrackFund fund in funds)
        {
            ListViewItem newFundItem = new ListViewItem(fund.symbol);
            newFundItem.SubItems.Add(fund.entryPrice.ToString());
            newFundItem.SubItems.Add(fund.currentPrice.ToString());

            this.list_Tracker.Items.Add(newFundItem);
        }
    }//END FRM_FUNDTRACKER WITH FUNDS

    private void btn_Done_Click(object sender, EventArgs e)
    {

        if (MessageBox.Show("Close Form?", "Close Form?", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
        {
            this.Dispose();
        } 

    }

}

}

基金类别:

namespace SCM_Addin
{
class Fund
{

    public String symbol { get; set; } //Symbol of the fund to be used
    private int fundRow { get; set; } //Fund's spot in the Stats Sheet.
    private String url1, url2, url3;
    private HtmlAgilityPack.HtmlDocument doc;
    private DataPuller puller;
    private Dictionary<String, String> fundStats;
    private SqlConnection conn;

    public Fund(String sym)
    {

        this.symbol = sym;
        this.doc = new HtmlAgilityPack.HtmlDocument();
        this.puller = new DataPuller();
        this.url1 = "http://finance.yahoo.com/q?s=" + this.symbol;
        this.url2 = "http://finance.yahoo.com/q/ks?s=" + this.symbol;
        this.url3 = "http://www.profitspi.com/stock-quote/" + this.symbol + ".aspx";
        this.fundStats = new Dictionary<string, string>();
        this.conn = null;


    }

TrackFund 类(扩展基金)

namespace SCM_Addin.Funds
{
class TrackFund : Fund
{

    public double entryPrice { get; set; }
    public double currentPrice { get; set; }

    public TrackFund(String sym, double entryP, double curP) : base(sym)
    {

        this.entryPrice = entryP;
        this.currentPrice = curP;

    }

}
}

这是我第一次真正在 C# 中扩展一个类,所以如果我扩展错误,我想可能是这样。

【问题讨论】:

    标签: c# accessibility


    【解决方案1】:

    公开TrackFund 类。

    public class TrackFund : Fund
    {
     ....
    }
    

    【讨论】:

      【解决方案2】:

      Default accessibility for a class will be internal,所以:

      class Fund
      //and
      class TrackFund : Fund
      

      ...应该是

      public class Fund
      //and
      public class TrackFund : Fund
      

      【讨论】:

      • 发生在我们所有人身上。 :-D
      猜你喜欢
      • 2013-09-12
      • 2013-06-20
      • 1970-01-01
      • 2011-04-28
      • 1970-01-01
      • 2015-07-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多