方法和属性之间有什么区别? [英] What is the difference between Methods and Property?

查看:89
本文介绍了方法和属性之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

方法和属性之间有什么区别?
请具体说明,它们之间有何不同?

What is the difference between Methods and Property?
Please be specific, How they differ from each other?

推荐答案

方法"是复数形式的作品,属性"是单数形式.您想要一对多还是多对一的比较? :-).如果您仍然没有得到提示:"{0}和{1}之间的区别是什么"的问题是不正确的.既学习又自己看,不要太懒.您需要学习概念,而不是比较它们.我真的不在乎这是在您的学校还是面试中提出的问题.我可以帮助学习,而不是回答不正确的问题.

如果这还不够,请阅读以下内容: http://msdn.microsoft.com/en-us/library/x9fsa0sw.aspx [ ^ ]和以下内​​容: http://msdn.microsoft.com/zh-cn/library/ms173114%28v = vs.80%29.aspx [
"Methods" is a work in the plural form, "Property" is in singular. What do you want one-to-many or many-to-one comparison? :-). If you still did not get a hint: the questions "What''s the difference between {0} and {1}" are not correct. Learn both and see by yourself, don''t be too lazy. You need to learn concepts, not compare them. I really don''t care if this is the question posed at your school or at an interview. I can help learning, not answering incorrect questions.

If this is still not enough, read this: http://msdn.microsoft.com/en-us/library/x9fsa0sw.aspx[^] and this: http://msdn.microsoft.com/en-us/library/ms173114%28v=vs.80%29.aspx[^]. Nothing is more specific than this. :-)

—SA


属性根本不像方法,因为定义了两个不同的代码段.一种用于读取或检索属性的值,一种用于写入或分配其属性.

方法的返回类型可以为void,而属性的类型不能为void.属性的get部分总是类似于无参数方法,而属性的set部分就像具有一个参数(值)的方法.

在方法中,如果两个具有相同参数的调用产生不同的结果,则通常是可接受的行为.在属性中,这仅适用于属性的阅读部分.

干杯!
A property is not at all like a method as there are two different code sections defined. One for reading or retrieving the propertie''s value and one for writing or assigning to it.

A method can have a return type of void whereas a property cannot be of type void. The get part of a property is always liken to a parameterless method whereas the set part of a property is like a method that has one parameter (value).

In methods it is generally acceptable behaviour if two calls with the same parameter yield different results. In properties this only applicable to the reading part of the property.

Cheers!


这篇关于方法和属性之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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