SoFunction
Updated on 2025-03-06

A brief discussion on the comparison of simple types of expression tree expression tree demo

A brief discussion on the comparison of simple types of expression tree expression tree demo

Updated: February 15, 2017 11:25:58 Submission: jingxian
Below, the editor will bring you a brief discussion on the simple type comparison of c# expression tree Expression. The editor thinks it is quite good, so I will share it with you now and give you a reference. Let's take a look with the editor

Examples are as follows:

using System;
using ;

class DynamicPredicate
{
  public static Expression<Func<T, T, bool>> Generate<T>(string op)
  {
    ParameterExpression x = (typeof(T), "x");
    ParameterExpression y = (typeof(T), "y");
    return <Func<T, T, bool>>
    (
      ((">")) ? (x, y) :
        (("<")) ? (x, y) :
          ((">=")) ? (x, y) :
            (("<=")) ? (x, y) :
              (("!=")) ? (x, y) :
                (x, y),
      x,
      y
    );
  }
}

static void Main()
  {
    string op = ">=";
    var integerPredicate = <int>(op).Compile();
    var floatPredicate = <float>(op).Compile();

    int iA = 12, iB = 4;
    ("{0} {1} {2} : {3}",
              iA, op, iB, integerPredicate(iA, iB));

    float fA = 867.0f, fB = 867.0f;
    ("{0} {1} {2} : {3}",
              fA, op, fB, floatPredicate(fA, fB));

    ("{0} {1} {2} : {3}",
              fA, ">", fB, <float>(">").Compile()(fA, fB));

    ();
  }

The above article briefly discusses the simple type comparison of c# expression tree Expression is all the content I have shared with you. I hope you can give you a reference and I hope you can support me more.

  • expression
  • Expression tree
  • c#

Related Articles

  • Detailed explanation of the use of user controls and custom controls in WPF

    Whether in WPF or WinForm, there are user controls (UserControl) and custom controls (CustomControl). Both controls are encapsulated by existing controls to reuse functions. However, there are still some differences between the two. This article explains these two controls
    2023-03-03
  • Implementation code for simply nested flash reading data in C#

    This article mainly introduces the implementation code of C#'s simple nested flash reading data. Friends who need it can refer to it.
    2013-11-11
  • c# method of config file operation class library

    Below, the editor will bring you a method of operating the class library of c# configuration file. The editor thinks it is quite good. I will share it with you now and give you a reference. Let's take a look with the editor
    2016-12-12
  • C# uses MiniExcel to implement import and export data to Excel/CSV files

    MiniExcel is a simple and efficient tool to avoid OOM to process Excel's search, write and fill data. This article mainly introduces how C# uses MiniExcel to import and export data to Excel/CSV files. If you need it, please refer to it.
    2024-02-02
  • Detailed tutorial on using RabbitMQ in C#

    RabbitMQ is a powerful message queue system that can be used to perform reliable message delivery in distributed systems. This blog will introduce in detail how to use RabbitMQ to implement various message queue operations in C#, and introduce it in a very detailed manner through the code. Friends who need it can refer to it.
    2024-08-08
  • Simple example of using C# semaphores

    This article mainly introduces the usage of C# semaphores, and combines the simple C# console application to analyze the functions, definitions, calls, releases and other operating techniques of semaphores. Friends who need it can refer to it
    2016-07-07
  • C# implements ini file read and write operations

    This article mainly introduces the reading and writing operations of C# ini files in detail, which has certain reference value. Interested friends can refer to it.
    2018-08-08
  • Port scanner instance code based on C# implementation

    This article mainly introduces the port scanner instance code based on C# implementation. Friends who need it can refer to it.
    2014-07-07
  • Detailed explanation of the use of c# dynamic

    This article mainly introduces the detailed explanation of the use of C# dynamic, which helps everyone better understand and learn how to use C#. Interested friends can learn about it.
    2021-04-04
  • C# Detailed explanation of the method of deleting a certain value or a set of values ​​in an array

    In this article, the editor will sort out the relevant knowledge points about how to delete a certain value or a set of values ​​in an array in C#. Friends who need it will learn it.
    2020-03-03

Latest Comments