本文介绍了语法问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在努力工作的公司正在尝试使用Microsoft发布的应用程序 数据块,以便为我们的.NET应用程序提供透明的数据库和b $ b连接。我的任务是完全理解代码。 。然而,当我浏览源代码时,我遇到了一段对我来说没有意义的代码 。我希望这里的某个人能够启发我。 有问题的代码在SqlDbHelper.vb文件中,位于 DiscoverSpParameterSet函数下: Dim cn As New SqlConnection(connectionString) Dim cmd As SqlCommand = New SqlCommand(spName,cn) Dim discoveredParameters()As IDataParameter 尝试 cn.Open() cmd.CommandType = CommandType.StoredProcedure SqlCommandBuilder.DeriveParameters(cmd) 如果不是includeReturnValueParameter那么 cmd.Parameters.RemoveAt(0) 结束如果 discoveredParameters = New SqlParameter(cmd.Parameters.Count - 1) {} cmd.Parameters.CopyTo(discoveredParameters,0) 最后 cmd.Dispose() cn.Dispose() 结束尝试 我不理解的一行是: discoveredParameters =新的SqlParameter(cmd.Parameters.Count - 1){} 我可以看到正在创建一个SqlParameter对象的实例。 但是,没有任何重载的构造函数匹配参数 给出。虽然在声明的最后是一个开始和结束 大括号({})。如果删除它,我确实得到了我刚才提到的预期的 错误。然而,有了这些花括号, 一切都很好。这里有什么成就?提前致谢 您可以提供的任何见解。 Robert 解决方案 " Robert Brinson" < RB ****** @ cox-internet.com> schrieb 我不理解的是: discoveredParameters = New SqlParameter(cmd.Parameters.Count - 1) {} 参数。虽然在声明的最后是一个开头和结束大括号({})。如果删除它,我确实得到了我刚才提到的预期错误。但是,有了这些卷曲的支撑,一切都很好。这里有什么成就?提前感谢您提供的任何见解。 我(也)认为这是语言不一致: ' '创建< type>的新实例,传递< args>到了ocnstructor。 var = New< type>(< args>) ''创建一个< type>的*数组*,上限是< args>,没有物品放入 数组: var = new< type>(< args>){} ''创建一个< typeY的*数组*,上限是< args>,一个项目放在 $ b $中b数组: var = new< type>(< args>){< Item>} - Armin http://www.plig .net / nnq / nquote.html http: //www.netmeister.org/news/learn2quote.html 嗨罗伯特, 我等了Armin,因为他上周长时间争论这个空字符串 。 但如果我是你,我确实把这条消息也放了它在t他/ b public.dotnet.framework.adonet新闻组。 许多活跃在该新闻组中的人特别知道来自 参数,较少受VB.language影响的人使用。 然后从2个方向的答案我认为你有最好的回应。 Cor *" Armin Zingler" < AZ ******* @ freenet.de> scripsit: 我可以看到正在创建一个SqlParameter对象的实例。但是,重载的构造函数都不匹配给定的参数。虽然在声明的最后是一个开头和结束大括号({})。如果删除它,我确实得到了我刚才提到的预期错误。但是,有了这些卷曲的支撑,一切都很好。这里有什么成就?提前感谢您提供的任何见解。我(也)认为这是语言不一致: 请指出什么' '不一致'行为...... ''创建< type>的新实例,传递< args>对于构造函数。 var = New< type>(< args>)''创建< type>的*数组*,上限是< args>, 数组中没有任何项目: var = new< type>(< args>){} ''''创建一个*数组* of< typeY,上限是< args> ;,一个项目放在数组中: var = new< type>(< args>){< Item>} - Herfried K. Wagner [MVP] < http://www.mvps.org / dotnet> The company I am working for is trying to work with the ApplicationData Blocks that Microsoft released to provide transparent databaseconnectivity for our .NET applications. I have been tasked with havinga thorough understanding of the code. However, while wading throughthe source, I came across a section of code that does not make senseto me. I was hoping that someone here would be able to enlighten me.The code in question is in the SqlDbHelper.vb file and is under theDiscoverSpParameterSet function:Dim cn As New SqlConnection(connectionString)Dim cmd As SqlCommand = New SqlCommand(spName, cn)Dim discoveredParameters() As IDataParameterTrycn.Open()cmd.CommandType = CommandType.StoredProcedureSqlCommandBuilder.DeriveParameters(cmd)If Not includeReturnValueParameter Thencmd.Parameters.RemoveAt(0)End IfdiscoveredParameters = New SqlParameter(cmd.Parameters.Count - 1){}cmd.Parameters.CopyTo(discoveredParameters, 0)Finallycmd.Dispose()cn.Dispose()End TryThe line I am not understanding is:discoveredParameters = New SqlParameter(cmd.Parameters.Count - 1) {}I can see that an instance of a SqlParameter object is being created.However, none of the overloaded constructors match the argumentsgiven. Though at the end of the statement are an opening and closingcurly brace ({}). If this is removed, I do indeed get the expectederror that I just mentioned. However, with these curly braces,everything is fine. What is being accomplished here? Thanks in advancefor any insight you can provide.Robert 解决方案 "Robert Brinson" <rb******@cox-internet.com> schrieb The line I am not understanding is: discoveredParameters = New SqlParameter(cmd.Parameters.Count - 1) {} I can see that an instance of a SqlParameter object is being created. However, none of the overloaded constructors match the arguments given. Though at the end of the statement are an opening and closing curly brace ({}). If this is removed, I do indeed get the expected error that I just mentioned. However, with these curly braces, everything is fine. What is being accomplished here? Thanks in advance for any insight you can provide.I (also) think this is a language inconsistency:''creates a new instance of <type>, passing <args> to the ocnstructor.var = New <type>(<args>)''creates an *array* of <type>, upper bound is <args>, no items are put inthearray:var = new <type>(<args>){}''creates an *array* of <typeY, upper bound is <args>, one item is put in thearray:var = new <type>(<args>){<Item>}--Armin http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html Hi Robert,I waited on Armin, because he had a long arguing about this empty stringlast week.But if I was you I did put this message also it in thepublic.dotnet.framework.adonet newsgroup.A lot of those who are active in that newsgroup knows especialy much fromthe parameters, which are less used by the more VB.language affected people.Then with the answers from 2 directions I think you have the best response.Cor* "Armin Zingler" <az*******@freenet.de> scripsit: I can see that an instance of a SqlParameter object is being created. However, none of the overloaded constructors match the arguments given. Though at the end of the statement are an opening and closing curly brace ({}). If this is removed, I do indeed get the expected error that I just mentioned. However, with these curly braces, everything is fine. What is being accomplished here? Thanks in advance for any insight you can provide. I (also) think this is a language inconsistency:Please point out what''s "inconsistent" behavior... ''creates a new instance of <type>, passing <args> to the ocnstructor. var = New <type>(<args>) ''creates an *array* of <type>, upper bound is <args>, no items are put in the array: var = new <type>(<args>){} ''creates an *array* of <typeY, upper bound is <args>, one item is put in the array: var = new <type>(<args>){<Item>}--Herfried K. Wagner [MVP]<http://www.mvps.org/dotnet> 这篇关于语法问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-19 17:39