Click here to Skip to main content
15,914,010 members
Home / Discussions / C#
   

C#

 
AnswerRe: Regular Expression pattern Pin
Ravi Sant17-Dec-10 0:20
Ravi Sant17-Dec-10 0:20 
GeneralRe: Regular Expression pattern Pin
Hiren solanki17-Dec-10 0:22
Hiren solanki17-Dec-10 0:22 
GeneralRe: Regular Expression pattern Pin
NarVish17-Dec-10 0:37
NarVish17-Dec-10 0:37 
GeneralRe: Regular Expression pattern Pin
Hiren solanki17-Dec-10 0:43
Hiren solanki17-Dec-10 0:43 
GeneralRe: Regular Expression pattern Pin
NarVish17-Dec-10 0:32
NarVish17-Dec-10 0:32 
AnswerRe: Regular Expression pattern Pin
Pete O'Hanlon17-Dec-10 0:37
mvePete O'Hanlon17-Dec-10 0:37 
GeneralRe: Regular Expression pattern Pin
NarVish17-Dec-10 1:05
NarVish17-Dec-10 1:05 
GeneralRe: Regular Expression pattern Pin
Pete O'Hanlon17-Dec-10 2:31
mvePete O'Hanlon17-Dec-10 2:31 
QuestionVSTO Word add-in 2007 Range.Find from background thread or worker Pin
Dino Mulahusic16-Dec-10 22:44
professionalDino Mulahusic16-Dec-10 22:44 
QuestionImage Upload and Resize Pin
Sudipta K Paik16-Dec-10 21:59
Sudipta K Paik16-Dec-10 21:59 
AnswerRe: Image Upload and Resize Pin
OriginalGriff16-Dec-10 22:16
mveOriginalGriff16-Dec-10 22:16 
JokeRe: Image Upload and Resize [modified] Pin
_Erik_17-Dec-10 3:21
_Erik_17-Dec-10 3:21 
QuestionEnumeration as Indexer: Is C# not the strongly-typed? Pin
Paul Selormey16-Dec-10 20:07
Paul Selormey16-Dec-10 20:07 
AnswerRe: Enumeration as Indexer: Is C# not the strongly-typed? Pin
harold aptroot16-Dec-10 21:58
harold aptroot16-Dec-10 21:58 
GeneralRe: Enumeration as Indexer: Is C# not the strongly-typed? Pin
Paul Selormey16-Dec-10 23:40
Paul Selormey16-Dec-10 23:40 
AnswerRe: Enumeration as Indexer: Is C# not the strongly-typed? Pin
Eddy Vluggen16-Dec-10 22:06
professionalEddy Vluggen16-Dec-10 22:06 
GeneralRe: Enumeration as Indexer: Is C# not the strongly-typed? [modified] Pin
Paul Selormey16-Dec-10 23:26
Paul Selormey16-Dec-10 23:26 
GeneralRe: Enumeration as Indexer: Is C# not the strongly-typed? Pin
Eddy Vluggen17-Dec-10 0:38
professionalEddy Vluggen17-Dec-10 0:38 
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 
As I know from OOP theory, the purpose of private Properties is to have the variables of an object protected from other classes, that could accidentaly change their value, thus provoking complications in a software. Am I correct till here?

Then I started to read C# and I found out that variables are called fields and they are also usually private. But there are also Properties with set and get which are used to change variables' (fields') values.

For instance:
I have a variable category in a class Myclass.

To follow strict C# grammar I write

private int cat;

and then I create a property with set and get

        public int Category<br />
        {<br />
            get { return cat;  }<br />
<br />
            set { cat = value; }<br />
        }


Therefore I can access the property from any other class using
Myobject.Category = 5

And here comes the question: why use such a complicated way? Why not use directly a public cat field? After all, cat is still not protected since I can directly change Category instead.

Thanks in advance for any reply.
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 

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.