了解C#类

扫码查看
本文介绍了了解C#类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对C#相当陌生,在理解类的某些方面时遇到了麻烦.例如,我有以下代码:

I am fairly new to C# and am having trouble understanding certain aspects of classes. For instance, I have the following code:

public partial class Budget : UserControl
    {
        public Budget ()                //
        {
            InitializeComponent();      // Constructor
        }                               //
    }

    public class BudgetClass
    {
        public BudgetClass(string category, long dollars)     // Constructor
        {                                                     // with
            this.category = category;                         // values
            this.dollars = dollars;                           // I am
        }                                                     // supplying.

        public string category { get; set; }       // Very confused here.
        public long dollars { get; set; }          // Not sure what this is doing??
    }

    public class ProposedBudgetCollection : Collection<BudgetClass>
    {
        public ProposedBudgetCollection()
        {
            Add(new BudgetClass("Total Personal Income", 0 )); // Adding objects
            Add(new BudgetClass("Net Salary", 5));             // with supplied
            Add(new BudgetClass("Bonuses", 5));                // data into List.
            Add(new BudgetClass("Money", 100));                //
        }
    }
}



谁能用简单的英语向我解释这里发生的事情?更重要的是,我对列表中发生的事情感到困惑.看来我正在实例化一个BudgetClass的新对象,并将要提供的值放入该对象中,然后将其添加到列表中.

我的最终目标是学习如何用来自单独窗口中文本字段的用户输入替换传递给列表的绝对数据.我可以很容易地将这些值传递给班级,但是我很难将它们添加到列表中.我觉得我需要先理解这一部分,然后才能继续.有人可以帮我吗?



Can anyone explain to me the "walkthrough" in plain English of what is going on here? More to the point, I am confused as to what is going on in the List. It seems that I am instantiating a new object of BudgetClass and placing the values that I am supplying into that object and then adding it to a list.

My ultimate goal is to learn how to replace the absolute data I am passing to the List with user input from a text field in a separate window. I can pass those values into my class easily enough, but I am having a very hard time adding them to the List. I feel that I need to understand this part before I can continue. Can anyone please help me?

推荐答案



这篇关于了解C#类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 18:16
查看更多