草庐IT

dynamic-linq

全部标签

c# - 如何使用 LINQ 获取数组中最大值的索引?

我有一个double组,我想要最高值的索引。这些是我到目前为止提出的解决方案,但我认为必须有一个更优雅的解决方案。想法?double[]score=newdouble[]{12.2,13.3,5,17.2,2.2,4.5};inttopScoreIndex=score.Select((item,indx)=>new{Item=item,Index=indx}).OrderByDescending(x=>x.Item).Select(x=>x.Index).First();topScoreIndex=score.Select((item,indx)=>new{Item=item,Inde

c# - IEnumerable<dynamic> 上的 LINQ Select 编译时错误

请进一步查看主要更新!我有这样的代码:voidTest(IEnumerablex){vardynX=x.Cast();varresult=dynX.Select(_=>_.Text);}在针对.NET4.5的现有库项目中。VS2015的IntelliSense强调了Text部分,提示:“对象”不包含“文本”的定义......果然,编译失败了errorCS1061:'object'doesnotcontainadefinitionfor'Text'andnoextensionmethod'Text'acceptingafirstargumentoftype'object'couldbef

c# - IEnumerable<dynamic> 上的 LINQ Select 编译时错误

请进一步查看主要更新!我有这样的代码:voidTest(IEnumerablex){vardynX=x.Cast();varresult=dynX.Select(_=>_.Text);}在针对.NET4.5的现有库项目中。VS2015的IntelliSense强调了Text部分,提示:“对象”不包含“文本”的定义......果然,编译失败了errorCS1061:'object'doesnotcontainadefinitionfor'Text'andnoextensionmethod'Text'acceptingafirstargumentoftype'object'couldbef

c# - Powershell 模块 : Dynamic mandatory hierarchical parameters

所以我真正想要的是在PS模块中有点可用的制表符补全。ValidateSet似乎是去这里的方式。不幸的是我的数据是动态的,所以我不能预先用所有有效值注释参数。DynamicParameters/IDynamicParameters似乎是那个问题的解决方案。将这些东西放在一起(并将我的失败归结为一个简单的测试用例)我们最终得到:usingSystem;usingSystem.Collections.Generic;usingSystem.Collections.ObjectModel;usingSystem.Linq;usingSystem.Management.Automation;us

c# - Powershell 模块 : Dynamic mandatory hierarchical parameters

所以我真正想要的是在PS模块中有点可用的制表符补全。ValidateSet似乎是去这里的方式。不幸的是我的数据是动态的,所以我不能预先用所有有效值注释参数。DynamicParameters/IDynamicParameters似乎是那个问题的解决方案。将这些东西放在一起(并将我的失败归结为一个简单的测试用例)我们最终得到:usingSystem;usingSystem.Collections.Generic;usingSystem.Collections.ObjectModel;usingSystem.Linq;usingSystem.Management.Automation;us

c# - 带有 HtmlAgilityPack 的 HTML Linq,或 P​​CL 中的替代方案

我已经在.NET4上编写了一个项目,目前正在让它也能在WindowsPhone上运行。我正在使用HtmlAgilityPack,这是一个著名的库,它允许通过HTML进行Linq查询,并且我只使用它提供的LoadHtml和Linq接口(interface)。将类库从.NET4转换为支持.NET4和WP8的PCL(可移植类库)后,我似乎不能再使用HtmlAgilityPack库了。有没有一种方法可以让HtmlAgilityPack在PCL项目下正常运行,或者是否有一个具有类似Linq界面的可变替代方案可以按预期工作?编辑:HtmlAgilityPack提供了9个不同的版本,其中没有一个与P

c# - 带有 HtmlAgilityPack 的 HTML Linq,或 P​​CL 中的替代方案

我已经在.NET4上编写了一个项目,目前正在让它也能在WindowsPhone上运行。我正在使用HtmlAgilityPack,这是一个著名的库,它允许通过HTML进行Linq查询,并且我只使用它提供的LoadHtml和Linq接口(interface)。将类库从.NET4转换为支持.NET4和WP8的PCL(可移植类库)后,我似乎不能再使用HtmlAgilityPack库了。有没有一种方法可以让HtmlAgilityPack在PCL项目下正常运行,或者是否有一个具有类似Linq界面的可变替代方案可以按预期工作?编辑:HtmlAgilityPack提供了9个不同的版本,其中没有一个与P

c# - Linq ExecuteCommand 不理解空值

我在使用linq将空值传递给ExecuteCommand()方法时遇到问题。我的代码类似于以下代码:publicvoidInsertCostumer(stringname,intage,stringaddress){ListmyList=newList();myList.Add(name);myList.Add(age);myList.Add(address);StringBuilderqueryInsert=newStringBuilder();queryInsert.Append("insertintoCustomers(name,address)values({0},{1},{2

c# - Linq ExecuteCommand 不理解空值

我在使用linq将空值传递给ExecuteCommand()方法时遇到问题。我的代码类似于以下代码:publicvoidInsertCostumer(stringname,intage,stringaddress){ListmyList=newList();myList.Add(name);myList.Add(age);myList.Add(address);StringBuilderqueryInsert=newStringBuilder();queryInsert.Append("insertintoCustomers(name,address)values({0},{1},{2

c# - 为什么调用 ISet<dynamic>.Contains() 编译,但在运行时抛出异常?

请帮我解释以下行为:dynamicd=1;ISets=newHashSet();s.Contains(d);代码编译时没有错误/警告,但在最后一行出现以下异常:UnhandledException:Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:'System.Collections.Generic.ISet'doesnotcontainadefinitionfor'Contains'atCallSite.Target(Closure,CallSite,ISet`1,Object)atSystem.Dynamic.Update