简体   繁体   中英

Issue with getters and setters Methods

In my CustomView class, TaskText and ProjectText are comboboxes. See the following property written for getting value from TaskText . My TaskText combobox contains list of Tasks. When I select specific task at runtime, it should store id of that Task which I've done in setters. But I don't understand, how do I get that id?

Later, I'll convert that id to integer and passed to method.

See the below code, which I've tried-

public Harvest_Task taskClass
{
    get
    {
        return new Harvest_Task { _id = Int32.Parse(TaskText.Text) }; // Here _id doesn't take the value.
    }
    set
    {
        if (value != null)
        {
            TaskText.Text = (value._id).ToString();             
        }
    }
} 

通常,您为类的特定属性而不是整个类本身创建一个getter / setter方法...再加上您尝试做事的方式,我建议尝试Singleton类。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM