为什么对象类需要受保护的方法?

时间:2018-04-16 15:03:50

标签: c# .net oop

Object是从中派生每个其他类的基类。其中,它具有受保护的访问修饰符(即MemberwiseClone())的方法  protected表示可以从声明它的类中以及从声明该成员的类派生的任何类中访问该成员。

这是否意味着Object所有受保护的成员实际上都是公开的?如果是,为什么要实施?

1 个答案:

答案 0 :(得分:-2)

不,这并不意味着他们会公开。这意味着从该类派生的任何类都可以使用受保护的方法。

    private void bind10()
{
            //Fetch the Statistical data from database.
            string query = "SELECT status, DATEPART(Month, Date) as [Year], COUNT(weightedValue) as [Total]";
query += " FROM SalesActivity INNER JOIN STATUS ON SalesActivity.Status_ID = STATUS.Status_ID  WHERE status IN ('Request for info', 'Quotation', 'Negotiating','Order Placed', 'Lost' )";
            query += " GROUP BY status, DATEPART(Month, Date)";
            DataTable dt = GetData(query);

//Get the DISTINCT Countries.
List<string> statuses = (from p in dt.AsEnumerable()
                          select p.Field<string>("status")).Distinct().ToList();

            //Loop through the Countries.
            foreach (string status in statuses)
            {

                //Get the Year for each Country.
                int[] x = (from p in dt.AsEnumerable()
                           where p.Field<string>("status") == status
                           orderby p.Field<int>("Year") ascending
                           select p.Field<int>("Year")).ToArray();

//Get the Total of Orders for each Country.
int[] y = (from p in dt.AsEnumerable()
           where p.Field<string>("status") == status
           orderby p.Field<int>("Year") ascending
           select p.Field<int>("Total")).ToArray();

//Add Series to the Chart.
Chart10.Series.Add(new Series(status));
                Chart10.Series[status].IsValueShownAsLabel = true;
                Chart10.Series[status].ChartType = SeriesChartType.StackedColumn;
                Chart10.Series[status].Points.DataBindXY(x, y);

                Chart10.Legends[0].Enabled = true;
            }
        }