Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
code in the code behind class

C#
Transition trns = new Transition();
        trns.StageFromId = 1671;



code in the class of Transition

C#
public int StageFromId
{
        private get { return _stageId; }
        set { _stageId = value; }
}


its not initializing the value 1671 to the variable. but when i do the same thing in the constrctor in the class it works why?
Posted
Updated 10-Aug-11 5:51am
v2
Comments
BoxyBrown 10-Aug-11 11:55am    
I think "private get" is bad thing anyway.

If you have a property that can only be set you should do so from the constructor.
 
Share this answer
 
v3
Comments
Andrew Rissing 10-Aug-11 12:47pm    
You might want to validate your claim there about the getter always being called because its not true. Unless you did something like "StageFromId++" (which is just syntactic sugar for "StageFromId = StageFromId + 1") a getter will never be called on a set.
[no name] 10-Aug-11 12:51pm    
Yes, my mistake. I was thinking of something else and confusing my project. So much for multi-tasking :)
Andrew Rissing 10-Aug-11 12:53pm    
Np, updated vote/etc./etc.
I would approach this from the debugger and see if you're indeed referencing the same classes as you would expect. They're shouldn't be any issue with what you've posted, but I'm betting it is a situation of referencing the wrong value or some other code is updating that value.

To second BoxyBrown, "private get"s are goofy in my book as well. I like to call those kinds of property's black holes. You can put anything you want into them, but nothing comes out. ;)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900