属性的用途和区别? [英] Uses and differences in properties?
本文介绍了属性的用途和区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好!
c#中的自动实现属性和手动属性之间有什么区别?
例如:
手册属性:
Hi Guys!!!
whats difference between Auto-Implemented Properties and manual properties in c#?
for Example:
Manual Properties:
private int uno;
public int Uno
{
get { return uno; }
set { uno = value; }
}
自动实施的道具:
Auto Implemented Prop:
public string UserLeaveCount { get; set; }
问候
sarva
regards
sarva
推荐答案
不多.自动实现的属性只是编译器的语法简写.如果您使用ILSpy之类的工具查看程序集,则会看到自动实现的属性实际上在编译时便转换为property + backing字段.
http://msdn.microsoft.com/en-us/library/bb384054.aspx [ ^ ]
http://ilspy.net/ [ ^ ]
现实中唯一的区别是,手动属性可以在赋值或返回值之前使用该值执行操作. auto属性只是设置或返回值.
Not much. Auto implemented properties are simply syntactic shorthand for the compiler. If you look at the assembly using a tool like ILSpy, you''ll see that an auto implemented property actually gets converted to property + backing field at compile time.
http://msdn.microsoft.com/en-us/library/bb384054.aspx[^]
http://ilspy.net/[^]
The only real-world difference is that a manual property can do things with the value before it is assigned or returned. An auto property just sets or returns the value.
这篇关于属性的用途和区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文