如何在LINQ中动态写在哪里?

编程入门 行业动态 更新时间:2024-10-25 22:34:08
本文介绍了如何在LINQ中动态写在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个如下的LinQ查询

I have a LinQ query as below

var filtered=from c in country where c.Id>=5 select c;

现在我需要让运算符``> =''是动态的,即运算符可能是``> =''或``==''或``< =''等,具体取决于条件和查询应基于该运算符执行.

Now i need to have the operator ''>='' to be dynamic i.e., the operator may be ''>='' or ''=='' or ''<='' etc depending on a certain criteria and the query should execute based on that operator. How to achieve this in LinQ?

推荐答案

您可以添加一个返回bool的检查功能. 像这样的东西: Hi, You could add a check-function which returns a bool. Something like this: private bool TestValue(int id, int contiditon) { if (condition == 1) { return id <= 5; } else { return id >= 5; } } /* your linq query would look like this */ var filtered = from c in country where TestValue(c.Id, c.Condition) select c;

这是完全未经测试的,因此可能包含错误;) 希望这会有所帮助. 致以诚挚的问候,祝您编程愉快, 停止

This is completely untested so it could contain errors ;) Hope this helps. Best regards and happy coding, Stops

如何在水晶报表中使用关闭按钮 How to use the close button in crystal report

更多推荐

如何在LINQ中动态写在哪里?

本文发布于:2023-11-16 21:55:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1607625.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:写在   动态   如何在   LINQ

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!