getter and setter, get{} I need help understanding
getter and setter, get{} I need help understanding
Could someone help me out. I am trying to understand something. Look at the get methods in this class. (I think it is called a getter). This is confusing me, because I am working with data binding and in the example code, they never seem to explicitly call the get method to return the examNumber and examName. Instead these methods seem to be called implicitly somehow. Anyway, can someone help me to understand this more. Thank's in advance, Will
public
class Exam {
private String examNumber;
private String examName;
public String ExamNumber
{
get
{
return examNumber;
}
} public String ExamName {
get
{
return examName;
} }
public Exam(String strExamNumber,String strExamName) {
examNumber = strExamNumber;
examName = strExamName;
// // TODO: Add constructor logic here // }
}
getter and setter, get{} I need help understanding
BuffaloJ
e prope
in your code you set the properties as well, but in the method you confused
usage of properties for accessing attributes.As posted before, u can access like that :
string examName = exam.ExamName;
string examNumber = exam.ExamNumber;
---------------------------------------
TimothyJ
Exam exam = ...;
string examName = exam.ExamName;
string examNumber = exam.ExamNumber;
The compiler converts this to something like...
Exam exam = ...;
string examName = exam._getExamName();
string examNumber = exam._getExamNumber();
see http://msdn.microsoft.com/library/default.asp url=/library/en-us/csref/html/vclrfUsingProperties.asp