构造函数中可以使用什么逻辑? [英] What logic can be used in constructor?

查看:237
本文介绍了构造函数中可以使用什么逻辑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用分配的连接对象在构造函数中建立连接.除此以外,还可以在构造函数中使用

I used assigned connection object to establish connection in constructor.other than this what else can be used in constructor

推荐答案

我建​​议不要从构造函数中打开连接,而是在需要获取数据时打开Connection.

在构造函数中,只需创建一个Connection对象并对其进行缓存.每当需要获取数据并在读取数据后也将其关闭时,请使用此对象.

在销毁对象期间,处置连接对象. :)
I would recommend not to open Connection from Constructor, rather open Connection when you need to fetch data.

In Constructor, just create a Connection object and cache it. Use this object whenever you need to fetch data and also close it after you read data.

During object destruction, Dispose the connection object. :)


没有规则说明需要在构造函数中放入哪些代码.它完全基于您的应用程序需求.基本的理解是放置可以在对象初始化时完成的操作.
There is no rule stating that which code you need to put in constructor. Its totally based on your application requirement. The basic understanding is to put the operations which can be done at the time of object initialization.


问题对我来说不是很清楚,但希望下面的链接对您有所帮助:
http://www.dotnetspider.com/forum/171656-what-c​​onstructor-uses- Purpose.aspx [ ^ ]
Question is not very clear to me but hope below link helps you:
http://www.dotnetspider.com/forum/171656-what-constructor-uses-Purpose.aspx[^]


这篇关于构造函数中可以使用什么逻辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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