Click here to Skip to main content
15,884,425 members
Home / Discussions / C#
   

C#

 
GeneralRe: Enumeration as Indexer: Is C# not the strongly-typed? Pin
Paul Selormey17-Dec-10 0:48
Paul Selormey17-Dec-10 0:48 
GeneralRe: Enumeration as Indexer: Is C# not the strongly-typed? Pin
harold aptroot17-Dec-10 1:13
harold aptroot17-Dec-10 1:13 
GeneralRe: Enumeration as Indexer: Is C# not the strongly-typed? Pin
Paul Selormey17-Dec-10 1:19
Paul Selormey17-Dec-10 1:19 
GeneralRe: Enumeration as Indexer: Is C# not the strongly-typed? Pin
Eddy Vluggen17-Dec-10 1:49
professionalEddy Vluggen17-Dec-10 1:49 
QuestionWhat's the purpose to use Property with set and get to change a field? Pin
nstk16-Dec-10 19:29
nstk16-Dec-10 19:29 
AnswerRe: What's the purpose to use Property with set and get to change a field? Pin
JF201516-Dec-10 20:02
JF201516-Dec-10 20:02 
GeneralRe: What's the purpose to use Property with set and get to change a field? Pin
nstk16-Dec-10 23:01
nstk16-Dec-10 23:01 
GeneralRe: What's the purpose to use Property with set and get to change a field? Pin
Jeff Connelly17-Dec-10 6:09
Jeff Connelly17-Dec-10 6:09 
nstk wrote:
The word 'Category' has a meaning for my class, but I am obliged to use a different word for the field, therefore I chose cat, but I find it poor in a semantic way.


Typically you will use Category for the property name and category or _category for the local variable name.

The same OO concept existed in C++ - it was simply a public method though. Properties are not necessary, it's just a new way of saying "public method that returns a value and keeps the value private." In C++ you'd simply write a public function, and some people even used the word "Get".

public int GetCategory()
{
return category;
}

public void SetCategory(int i)
{
category = i;
}

Same thing. However C# property offers you a convenient way of not even declaring the local variable! For example this works without even declaring your local variable called "cat".

public int Category
{
get;
set;
}

Again, this is for future use, where you have the option of changing how Category gets implemented (you can add a variable later, or write the get or set methods with some different code, but the caller would never need to know.) In the mean time, the compiler generates a local variable under the covers for you.
AnswerRe: What's the purpose to use Property with set and get to change a field? Pin
Hiren solanki16-Dec-10 23:52
Hiren solanki16-Dec-10 23:52 
GeneralRe: What's the purpose to use Property with set and get to change a field? Pin
Jeff Connelly17-Dec-10 6:15
Jeff Connelly17-Dec-10 6:15 
GeneralRe: What's the purpose to use Property with set and get to change a field? Pin
PIEBALDconsult17-Dec-10 7:50
mvePIEBALDconsult17-Dec-10 7:50 
GeneralRe: What's the purpose to use Property with set and get to change a field? Pin
kevinnicol17-Dec-10 7:53
kevinnicol17-Dec-10 7:53 
GeneralRe: What's the purpose to use Property with set and get to change a field? [modified] Pin
Jeff Connelly17-Dec-10 8:21
Jeff Connelly17-Dec-10 8:21 
GeneralRe: What's the purpose to use Property with set and get to change a field? Pin
kevinnicol17-Dec-10 8:23
kevinnicol17-Dec-10 8:23 
GeneralRe: What's the purpose to use Property with set and get to change a field? Pin
Jeff Connelly17-Dec-10 8:39
Jeff Connelly17-Dec-10 8:39 
GeneralRe: What's the purpose to use Property with set and get to change a field? Pin
kevinnicol17-Dec-10 8:47
kevinnicol17-Dec-10 8:47 
GeneralRe: What's the purpose to use Property with set and get to change a field? Pin
Jeff Connelly17-Dec-10 8:50
Jeff Connelly17-Dec-10 8:50 
GeneralRe: What's the purpose to use Property with set and get to change a field? Pin
Toli Cuturicu17-Dec-10 15:00
Toli Cuturicu17-Dec-10 15:00 
GeneralRe: What's the purpose to use Property with set and get to change a field? Pin
Jeff Connelly20-Dec-10 4:21
Jeff Connelly20-Dec-10 4:21 
AnswerRe: What's the purpose to use Property with set and get to change a field? Pin
PIEBALDconsult17-Dec-10 2:28
mvePIEBALDconsult17-Dec-10 2:28 
AnswerRe: What's the purpose to use Property with set and get to change a field? Pin
Jeff Connelly17-Dec-10 6:03
Jeff Connelly17-Dec-10 6:03 
QuestionHow can I start with C/S programming? [modified] Pin
zouleisheng16-Dec-10 19:09
zouleisheng16-Dec-10 19:09 
AnswerRe: How can I start with C/S programming? Pin
Richard MacCutchan16-Dec-10 22:52
mveRichard MacCutchan16-Dec-10 22:52 
GeneralRe: How can I start with C/S programming? Pin
zouleisheng16-Dec-10 23:52
zouleisheng16-Dec-10 23:52 
GeneralRe: How can I start with C/S programming? Pin
Richard MacCutchan17-Dec-10 1:34
mveRichard MacCutchan17-Dec-10 1:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.