我的应用程序有n层体系结构。我有不同的层次(业务逻辑&数据链接& GUI)。我正在使用一些常用的类将数据从一个层传递到另一个层。我有一个班(说RetrnValueCls
),它只有两个变量Return value
和Return Message
。当我将数据从一层传递到另一层时,我需要返回这个Return Value
类以及其他类(比如说MasterItemsCls
),该类有其他变量。在c#中,是否有可能将两个不同的类作为返回类型从一个图层传递到其他图层?
下面是方法
public MasterItemsCls GetMasterItemsMDL()
{
/* Does some computations and assign them to
attributes of MasterItemsCls and pass it other methods in other layers. */
}
public ReturnValueCls GetMasterItemsMDL()
{
/* Does some computations and assign them to
attributes of ReturnValueCls and pass it other methods in other layers. */
}
我想作为返回类型返回上述两个类(MasterItemsCls
& ReturnValueCls
)的方法GetMasterItemsMDL
一次,也是我不想两个类结合起来。请让我知道我是否有办法做到这一点。
+1注意代码是如何有时不可读得到的,如果你在C#中使用'Tuple's。例如'tuple.Item1 + tuple.Item2 - 元组。Item3'将可读性带走 – 2013-03-15 16:47:55
@IlyaIvanov:元组可以很方便,但通常我会花时间创建一个自定义类。 – 2013-03-15 16:48:54
同意,主观,但我认为元组是将用F#编写的部分与C#代码集成的好方法。 F#有一个很好的处理元组的机制,比如模式匹配。我试图在一个项目中加入元组,但不超过两个通用参数,而且很少。 – 2013-03-15 16:50:49