为什么我们要使用自己的类作为参数或方法的返回类型? [英] Why would we use our own class as a parameter or return type on a method ?

查看:77
本文介绍了为什么我们要使用自己的类作为参数或方法的返回类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下使用类作为返回类型(复合类型),并且还用作参数类型)

1.CompositeType GetDataUsingDataContract(CompositeType复合);


公共CompositeType GetDataUsingDataContract(CompositeType复合)
{
}


使用类作为参数类型有什么好处?

below used class as return type(compositetype)and it is used as parameter type also)

1.CompositeType GetDataUsingDataContract(CompositeType composite);


public CompositeType GetDataUsingDataContract(CompositeType composite)
{
}


what are the advantages of using class as parameter type

推荐答案

我建​​议您购买一本基本的OO书并阅读.我看不到如何在论坛回复中进行介绍.

例如,如果您所需的只是该类的单个属性,则将对象传递给方法可能是懒惰的.例如,将类的表示存储到数据库中的方法也很有意义.类只是一个对象,它与内置类型(例如int和string)的等级相同.如果需要使用某种方法来处理它,则将其传递给它.如果在类中生成它,则将其返回.确实没有比这更复杂.
I suggest you buy a basic OO book and read it. I don''t see how I can cover this in a forum reply.

Passing an object into a method can be lazy, for example, if all you need is a single property off that class. It can also make sense, for example, a method that stores a representation of the class into the database. A class is just an object, it has equal ranking to the types that are built in, such as int and string. You pass it in if you need to work on it in a method. You return it, if you generate it in the class. It''s really not more complex than that.


这篇关于为什么我们要使用自己的类作为参数或方法的返回类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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