So I am getting myself confused with setter and getter vs. a public variable. I realize that I have not used setter and getter ;-0
What is the use of getter and setters vs. public variable? I understand its' about encapsulation and data validation, but I still don't see any single example that will use getter and setter over a public variable.
I also use a lot of methods that pass parameters to return some result. Could someone point me to a nice easy understand example from a web development stand point?
Say a registration page asking for FirstName and LastName textfields, how would you use getter and setter to accomplish this? Instead of having a method below
in the code behind I can access that information by calling classname.returnFullname.fullname;Code:public string fullname; public string returnFullname(string fname, string lname) fullname = fname & lname; return fullname;




Reply With Quote