|
-
May 16th, 2012, 01:33 PM
#1
C# Properties Question
Hello, I am an intermediate Java programmer and I have some questions about Properties that I cannot find anywhere. From what I gather, they are similar to Java's getter and setter methods, but seem like they may be more powerful.
Code:
private string color;
public string Color
{
get
{
return color.ToUpper();
}
set
{
if(value == "Red")
color = value;
else
Console.WriteLine("This car can only be red!");
}
}
This allows you to set the private string color to any string. I am just curious about how you would call such a method? How you differentiate between setting and getting when you make the call. Where is the variable "value" coming from?
Just some things that I would like to clarify before I move on. Thank you for any help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|