|
-
April 1st, 2008, 07:56 PM
#4
I know this is a bit late, but here's another reason - making stuff "readonly". Say you have a collection in your class and you want people to be able to access it, but you don't want them to be able to alter the actual reference:
Code:
public class MyClass
{
private ArrayList myList;
public ArrayList List
{
get
{
return myList;
}
}
public MyClass()
{
myList = new ArrayList();
}
}
Not the best example ever, but it means that they can add/remove/etc stuff from the collection, but they can't change which collection myList points to.
To answer your other question, as far as I know, the C# compiler will take your property and generate a get_MyProperty() method and a set_MyProperty() method. If you download Reflector you can see this by opening an assembly (either a CLR .dll or .exe) and looking for a property then expanding it. It'll also let you view the CIL that's generated for it.
ac
Last edited by gothic_type; April 1st, 2008 at 08:04 PM.
Similar Threads
-
By avdven in forum Web Development
Replies: 1
Last Post: July 24th, 2002, 06:18 AM
-
By Mankan in forum Other Tutorials Forum
Replies: 8
Last Post: July 23rd, 2002, 02:43 PM
-
By Negative in forum Other Tutorials Forum
Replies: 13
Last Post: July 11th, 2002, 10:03 PM
-
By jcdux in forum Microsoft Security Discussions
Replies: 0
Last Post: April 12th, 2002, 11:23 AM
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
|
|