Acquiring a property value
-
Truthfully? Not even close. Sorry, but you've got some more work to do.
A guide to posting questions on CodeProject[^]
Dave KreskowiakLike I said, I'm only about halfway through my book… I went back over the book, I didn't find anything in there talking about using properties on different data types… There were a few examples, only on string and int… Maybe, just maybe… It talks about using properties on different data types further in the book. Also, I just got done scouring MSDN and couldn't find anything that talks about using properties on different data types… I also click through the related topics and subjects, still couldn't find anything… Could you point me to a place online or if you have time… Explain it to me here. It would definitely be appreciated for your help. I would like to learn C sharp the right way, I want to be able to write the code myself… I don't want to be a script kiddie!
-
Like I said, I'm only about halfway through my book… I went back over the book, I didn't find anything in there talking about using properties on different data types… There were a few examples, only on string and int… Maybe, just maybe… It talks about using properties on different data types further in the book. Also, I just got done scouring MSDN and couldn't find anything that talks about using properties on different data types… I also click through the related topics and subjects, still couldn't find anything… Could you point me to a place online or if you have time… Explain it to me here. It would definitely be appreciated for your help. I would like to learn C sharp the right way, I want to be able to write the code myself… I don't want to be a script kiddie!
Properties are just little bits of code that gets/sets a value or reference. You access them the exact same way no matter what the class exposing them is. Why use properties at all?? Property "setters" can be written to validate the value being passed in before it's used by the object. They can also be used to kick off other pieces of code, usually depending on the value being passed in. Every class exposes it's own set of properties and methods. What each one does is explained in the documentation for that class. For example, the String class, docs are here[^], only exposes two properties itself, Chars and Length. I don't really know what your having a problem with.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
Properties are just little bits of code that gets/sets a value or reference. You access them the exact same way no matter what the class exposing them is. Why use properties at all?? Property "setters" can be written to validate the value being passed in before it's used by the object. They can also be used to kick off other pieces of code, usually depending on the value being passed in. Every class exposes it's own set of properties and methods. What each one does is explained in the documentation for that class. For example, the String class, docs are here[^], only exposes two properties itself, Chars and Length. I don't really know what your having a problem with.
A guide to posting questions on CodeProject[^]
Dave KreskowiakI get all of that, "Black Box" type of writing code… Hiding implementation. The only examples I've ever seen or talked about were on strings and ints… It never mentions other types like byte, long, boolean etc. etc. My question is I guess: can you use properties on all of those types?
-
I get all of that, "Black Box" type of writing code… Hiding implementation. The only examples I've ever seen or talked about were on strings and ints… It never mentions other types like byte, long, boolean etc. etc. My question is I guess: can you use properties on all of those types?
Can you use the properties exposed by those types (don't use "on"), yes of course! Using a property exposed by any type at all is exactly the same no matter what type it is.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak