简体   繁体   中英

accessing public variable inside protected method

I have public class and a public variable inside class.

public class Student 
{
    public string _firstName = null;

}

I have protected method in Student class where i am setting _firstName value

protected override void validate()
{

_firstName = "Test 1"
}

But, when i try to use _firstName value in another protected method of same class , it always gives null to me.

protected override string buildName()
{
    return String.Format("{0}_{1}", _firstName, _lastName);
}

Why? Am i missing some important concept here?

除非我误解了,否则您应该在方法中设置变量FullName,而不是_firstName。

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