本文介绍了属性或参数:性能最佳的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 你好, 当我开始使用VB6时,我曾经写过带有属性的类和 函数如下...... 私有lngf1为长 私有strf2为字符串 公共属性获取f1()为长 f1 = lngf1 结束物业 公共财产让f1(ByVal vnewvalue As Long) lngf1 = vnewvalue 结束属性 .... 公共函数DLInsertData(ConnStr As String,Provider As String))as as很长 错误GoTo Errorhandler Dim cnDB As ADODB.Connection Dim cmQ1 as ADODB.Command Set cnDB =新的ADODB.Connection cnDB.Provider = parProvider cnDB.ConnectionString = parConnStr cnDB.ConnectionTimeout = 10 cnDB.Open 设置cmQ1 =新ADODB.Command 设置cmQ1.ActiveConnection = cnDB cmQ1.CommandType = adCmdStoredProc cmQ1.Com mandText =" xx" cmQ1.Parameters.Refresh cmQ1.Parameters(1).Value = f1 cmQ1.Parameters(2 ).Value = f2 ...等 cmQ1.Execute DLInsertadvstabl = cmQ1.Parameters(45).Value cnDB.Close 设置cnDB =没什么 退出函数 错误处理程序: Err.Raise Err.Number,Err.Source,Err.Description 结束函数 所以我填写了类本身以外的属性,主要是通过赋值 形成属性的控制值,然后调用函数将数据插入数据库。 后来我学会了避免财产VB6类中的声明。有人告诉我 使用参数。所以我有没有属性的类,带有 函数的类,有很多像这样的参数... 公共函数DLInsertData(ConnStr As String,Provider As String,field1 As Long,field2 as string,etc)as Long On Error GoTo Errorhandler Dim cnDB As ADODB.Connection Dim cmQ1作为ADODB.Command 设置cnDB =新ADODB.Connection cnDB.Provider = parProvider cnDB。 ConnectionString = parConnStr cnDB.ConnectionTimeout = 10 cnDB.Open 设置cmQ1 =新ADODB.Command 设置cmQ1.ActiveConnection = cnDB cmQ1.CommandType = adCmdStoredProc cmQ1.CommandText =" xx" cmQ1.Parameters.Refresh cmQ1.Parameters(1).Value = field1 cmQ1.Parameters(2).Value = field2 ... etc cmQ1.Execute DLInsertadvstabl = cmQ1.Parameters(45).Value cnDB.Close 设置cnDB =没有什么 退出功能 错误处理程序: Err.Raise Err.Number,Err.Source,Err.Description 结束功能 据我所知,一旦DLL必须在n层环境中使用,这应该更加美好MTS或COM +。我相信系统有来为多个用户实例化的所有对象的属性保留空间,这可能会占用内存并与COM +原则发生冲突。 没有人确认过这个理论,我当时并不需要知道 当时的所有答案。 但是现在我开始使用ASP.NET了,我必须为更大的应用程序编写VB.NET代码,我想制作最好的代码。所以现在我想知道 上面的理论是否正确以及它是否也可以用点网提醒 。 那么,COM +仍然是dot net中的一个问题吗? 那么,我可以在ASP.NET中使用基于属性的对象吗? 或者我应该避免使用.vb中的属性使用 参数的类和使用函数以获得最佳性能? 非常感谢。 - 亲切的问候, Perre Van Wilrijk, 删除大写字母以获取我的真实电子邮件地址,Hi there,When I started using VB6, I used to write classes with properties andfunctions as following ...Private lngf1 As LongPrivate strf2 As StringPublic Property Get f1() As Longf1 = lngf1End PropertyPublic Property Let f1(ByVal vnewvalue As Long)lngf1 = vnewvalueEnd Property....Public Function DLInsertData(ConnStr As String, Provider As String)) as LongOn Error GoTo ErrorhandlerDim cnDB As ADODB.ConnectionDim cmQ1 As ADODB.CommandSet cnDB = New ADODB.ConnectioncnDB.Provider = parProvidercnDB.ConnectionString = parConnStrcnDB.ConnectionTimeout = 10cnDB.OpenSet cmQ1 = New ADODB.CommandSet cmQ1.ActiveConnection = cnDBcmQ1.CommandType = adCmdStoredProccmQ1.CommandText = "xx"cmQ1.Parameters.RefreshcmQ1.Parameters(1).Value = f1cmQ1.Parameters(2).Value = f2... etccmQ1.ExecuteDLInsertadvstabl = cmQ1.Parameters(45).ValuecnDB.CloseSet cnDB = NothingExit FunctionErrorhandler:Err.Raise Err.Number, Err.Source, Err.DescriptionEnd FunctionSo I populated the properties outside the class itself, mostly by assigningform control values to the properties, followed by calling the function toinsert data into the database.Later on I learned to avoid property declaration in VB6 Classes. I was toldto use parameters. So I had classes without properties, classes withfunctions with lot of parameters like this one ...Public Function DLInsertData(ConnStr As String, Provider As String, field1As Long, field2 as string, etc) as LongOn Error GoTo ErrorhandlerDim cnDB As ADODB.ConnectionDim cmQ1 As ADODB.CommandSet cnDB = New ADODB.ConnectioncnDB.Provider = parProvidercnDB.ConnectionString = parConnStrcnDB.ConnectionTimeout = 10cnDB.OpenSet cmQ1 = New ADODB.CommandSet cmQ1.ActiveConnection = cnDBcmQ1.CommandType = adCmdStoredProccmQ1.CommandText = "xx"cmQ1.Parameters.RefreshcmQ1.Parameters(1).Value = field1cmQ1.Parameters(2).Value = field2... etccmQ1.ExecuteDLInsertadvstabl = cmQ1.Parameters(45).ValuecnDB.CloseSet cnDB = NothingExit FunctionErrorhandler:Err.Raise Err.Number, Err.Source, Err.DescriptionEnd FunctionAs far as I remember this should be much beter once the DLL''s had to beplaced in n-tier environments using MTS or COM+. I believe the system hasto reserve space for the properties of all the objects instanceiated by themultiple users and that might eat memory and conflict with COM+ principles.Nobody has ever confirmed me this theory and I didn''t really need to knowall the answers at that time.But now I''m starting to use ASP.NET and I have to write VB.NET code forlarger applications, I want to make the best code I can. So now I wonderwhether the theory above is true and whether it''s also something to remindin dot net.So, is COM+ still an issue in dot net?So, may I use property based objects in ASP.NET?Or should I avoid properties in .vb classes and use functions withparameters in order to obtain the best performance?Thanks a lot.--Kind regards,Perre Van Wilrijk,Remove capitals to get my real email address,推荐答案 如果你想象你的代码在加利福尼亚州,并且所需的对象是在纽约的b 和两种方式之间发送信息的唯一方法就是给一只鸽子打上一张纸条并将其发送给它...... 你要去每当你需要访问一个鸽子时,你会发送一只鸽子,然后在发送另一只鸽子之前等待归来的鸽子吗? 或者你想要写所有的鸽子信息下来 在一张纸条中发送一只鸽子让该物体作出回应? 我的观点是,重要的是什么类型的边界你 计划跨越。 ASP听起来像是在使用互联网,或者至少是某种类型的网络,当然不是本地引用的对象。 在这种情况下,避免繁琐的对象(Chatty =强制要求的电话 正常使用;例如:设置属性),然后去参数化路线。 HTH LFSIf you imagine your code is in California, and a needed object is inNew York, and the only way to send messages between the two isto tie a note to a pigeon and send it on its way....Are you going to send off a pigeon every time you need to accessa property, and then wait for a return pigeon before sending off another?Or are you going to want to write all the information downin a note and send off one pigeon to get that object to respond?The point I am making is that it matters what kinds of boundries youplan to cross. ASP sounds like you''re using the internet, or at leasta network of some kind, certainly not a locally referenced object.In that case, avoid chatty objects (Chatty = forcing required callsfor normal use; ex: setting properties), and go the parameterized route.HTHLFS 这篇关于属性或参数:性能最佳的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-03 22:54
查看更多