为什么它没有在文件背后的代码中增加值 [英] Why its not assining the value in code behind file

查看:56
本文介绍了为什么它没有在文件背后的代码中增加值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在类后面的代码中的代码

code in the code behind class

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




过渡类中的代码




code in the class of Transition

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



它不会将值1671初始化为变量.但是当我在类中的构造函数中执行相同的操作时,为什么起作用?



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?

推荐答案

如果您具有只能设置的属性,则应从
If you have a property that can only be set you should do so from the constructor.


我将从调试器中解决这个问题,看看您是否确实在引用与您期望的类相同的类.它们不应该与您发布的内容有关,但是我敢打赌,这是引用错误值的情况,或者其他一些代码正在更新该值.

对于第二个BoxyBrown来说,私有获取"在我的书中也是愚蠢的.我喜欢称这类财产为黑洞".您可以将任何想要放入的东西放进去,但是什么也没有. ;)
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. ;)


这篇关于为什么它没有在文件背后的代码中增加值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆