无法在我的解决方案中的任何地方访问公共类的公共变量(VS,C'#)

时间:2014-08-07 09:03:21

标签: c# visual-studio variables constructor public

我接管了一个项目,我正在努力从公共类中访问公共变量。 (奇怪的)。

我对C#相对较新,只做了一些MVC,ASP.NET的东西,所以我不知道我是不是一个小丑但是:

public int AlertCount
{
    get { return Convert.ToInt32(alertCountTextBlock.Text); }
    set { alertCountTextBlock.Text = value.ToString(); }
}

/// <summary>
/// Property which represents the number of new alerts the project currently has 
/// </summary>
public int NewAlertCount
{
    get { return Convert.ToInt32(newAlertCountTextBlock.Text); }
    set { newAlertCountTextBlock.Text = value.ToString(); }
}

这是我试图从我的解决方案中的另一个类访问的两个变量(上图)

namespace Intelligence_Gathering_System.Pages.Project.Controls
{
    /// <summary>
    /// UserControl which acts as a selection button for each project. It displays the projects name and
    /// current alert item totals along with providing methods for sharing and selecting of the project
    /// </summary>
    public partial class ProjectHeaderControl 
    {
        private readonly ProjectPage _parentReference;                    //Reference to the controls 'parent' Project Page       

        /// <summary>
        /// Overloaded constructor which initialises the controls members
        /// </summary>
        /// <param name="projectName">The name of the project</param>
        /// <param name="alertCount">The total number of Alert Items in the project</param>
        /// <param name="newAlertCount">The total numebr of New Alert Items in the project</param>
        /// <param name="parent">A reference to the controls 'parent' Project Page</param>
        public ProjectHeaderControl(string projectName, int alertCount, int newAlertCount, ProjectPage parent)
        {

这是变量所在的类结构(名称空间,部分类和构造函数),

我只是试图从另一段代码(在同一个解决方案和项目中)调用来改变计数以增加和减少

Label im trying to increment seen here

我已经在类中尝试了我需要递增和递减(我需要执行多个类)然后将完整的命名空间路径放到变量中以精确定位它和类。变量(以下见例)

int x = Intelligence_Gathering_System.Pages.Project.Controls.NewAlertCount;

int x = ProjectHeaderControl.NewAlertCount;

它们都没有起作用,而且为什么会有点困惑。

我错过了这里明显的东西或...... 它是否与语法相关,因为C#i不确定。

任何帮助都将不胜感激。

此致

约旦

1 个答案:

答案 0 :(得分:3)

NewAlertCount中的属性 - 但我们无法分辨该类是什么。 (也许是ProjectHeaderControl - 你的描述有点难以理解。)

Intelligence_Gathering_System.Pages.Project.Controls名称空间。命名空间不能声明属性。

您需要指定包含属性的 - 它们需要是静态属性,或者您需要从实例班级。