代码参考1:

using System;
using System.Linq.Expressions; namespace ExpressionDemo
{
class People
{
public int Id { set; get; }
public string Name { set; get; }
}
class Program
{
static void Main(string[] args)
{
Expression<Func<People, bool>> expression = p => p.Id == 20;
Func<People, bool> func = expression.Compile();
bool bResult = func.Invoke(new People()
{
Id = 10,
Name = "张三"
});
Console.WriteLine(bResult); Expression<Func<int, int>> expression2 = (num) => num + 5;
Console.WriteLine($"NodeType:{expression2.NodeType}");
Console.WriteLine($"Body:{expression2.Body}");
Console.WriteLine($"Body Type: {expression2.Body.GetType()}");
Console.WriteLine($"Body NodeType: {expression2.Body.NodeType}");
}
}
}

参考代码2:

using System;

namespace EqualSoOnDemo
{
class People
{
private string name;
public string Name
{
get { return name; }
set { name = value; }
} public override bool Equals(object obj)
{
People p = obj as People;
if (this.Name == p.Name)
{
return true;
}
else
{
return false;
}
}
public People(string name)
{
this.name = name;
}
}
class Program
{
static void Main(string[] args)
{
string a = "hello";
string b = new string(new char[] { 'h', 'e', 'l', 'l', 'o' });
Console.WriteLine(a == b);
Console.WriteLine(a.Equals(b));
Console.WriteLine("\n");
Int32 m = 3;
Int32 n = 3;
Console.WriteLine(n == m);
Console.WriteLine(n.Equals(m));
Console.WriteLine("\n");
object g = a;
object h = b;
Console.WriteLine(g == h);
Console.WriteLine(g.Equals(h));
Console.WriteLine(g.GetHashCode() + " " + h.GetHashCode());
Console.WriteLine("\n");
People p1 = new People("Jimmy");
People p2 = new People("Jimmy");
Console.WriteLine("People...");
Console.WriteLine(p1 == p2);
Console.WriteLine(p1.Equals(p2));
Console.WriteLine(p1.GetHashCode() + " " + p2.GetHashCode());
Console.WriteLine("\n");
People p3 = new People("Jimmy");
People p4 = p3;
Console.WriteLine(p3 == p4);
Console.WriteLine(p3.Equals(p4));
}
}
}

参考博客:

https://www.cnblogs.com/zhaoshujie/p/15817805.html

Expression及Equal Demo的更多相关文章

  1. 用idea搭建一个简单的SSM的Demo

    1.新建一个maven  web app项目 结构如下 resources的资源文件如下 applicationContext.xml 的配置 <?xml version="1.0&q ...

  2. [C2P2] Andrew Ng - Machine Learning

    ##Linear Regression with One Variable Linear regression predicts a real-valued output based on an in ...

  3. [Spring]04_最小化Spring XML配置

    4.1 自动装配 Bean Spring 装配 bean 时,有时非常明确,就是需要将某个 bean 的引用装配给指定属性. 例如,若应用上下文中只有一个 javax.sql.DataSource 类 ...

  4. Entity FrameWork 6帮助类

    public class BaseDAL { string strConn = ""; public BaseDAL(string connString) { strConn = ...

  5. eclipse + maven 搭建springMVC+Spring+mybatis 系统

    首先需要下载maven 安装maven插件.自行百度. 1: 创建maven系统 http://huxiaoheihei.iteye.com/blog/1766986 2:添加pom依赖: pom.x ...

  6. Spring整合Hibernate详细步骤

    阅读目录 一.概述 二.整合步骤 回到顶部 一.概述 Spring整合Hibernate有什么好处? 1.由IOC容器来管理Hibernate的SessionFactory 2.让Hibernate使 ...

  7. EFsql笔记

    like的语法 string[] cities = { "London", "Madrid" }; IQueryable<Customer> cus ...

  8. [读行者][学习LinqExpression和Reflection(Emit)]阅读TypeBuilderSample之ExampleFromTheArticle

    前言 关于”读行者“ 俗语有云:"读万卷书,行万里路“.多读一些优秀代码,不仅可以锻炼我们读代码的能力(便于维护或相互交流),还可以吸取很多我们成长所需的知识点.多读,才能开阔我们的眼界,才 ...

  9. 学习并使用了两种linq to entity 的实现sql关键字in的查询方法

    //构造Lambda语句        private static Expression<Func<TElement, bool>> BuildWhereInExpressi ...

  10. entity framework 6 通用数据类

    原文  http://blog.csdn.net/laokaizzz/article/details/25730813 public class BaseDAL { string strConn = ...

随机推荐

  1. Security Bulletin: IBM WebSphere Application Server is vulnerable to a remote code execution vulnerability (CVE-2023-23477)

    Skip to content     Support     DownloadsDocumentationForumsCasesMonitoringManage support account   ...

  2. react组件传参记录,防止以后忘记,欢迎指正讨论

    c: 'Celsius', f: 'Fahrenheit' }; function toCelsius(fahrenheit) { return (fahrenheit - 32) * 5 / 9; ...

  3. vue 使用 swiper vue-awesome-swiper

    文档地址 https://github.com/surmon-china/vue-awesome-swiper 演示地址 https://v1.github.surmon.me/vue-awesome ...

  4. Supervisor安装及配置

    Supervisor安装 # 安装 easy_install supervisor # 生成默认配置文件 echo_supervisord_conf > /etc/supervisord.con ...

  5. C#如何将光标定位到文本框末尾(最后一位)

    代码如下:private void Movetoend(){//让文本框获取焦点this.TextBox1.Focus();//设置光标的位置到文本尾this.TextBox1.Select(this ...

  6. el-scrollbar 饿了么滚动条不出现 bug

    el-scrollbar 饿了么滚动条不出现 bug 解决方法:el-scrollbar 的直接子元素样式需要设置为 display: inline-block;

  7. 最好用的 vue v-for直接循环案例

    vue v-for直接循环数字,也就是固定次数 项目中需要做一个酒店星级,酒店星级就是固定的5星,根据后台返回的数据来显示几星级 <!--星级,循环固定次数 5次 根据酒店等级显示亮的星星和灰色 ...

  8. gRPC中protobuff type和C# type原生标量对应表

    查看Microsoft官方文档: Create Protobuf messages for .NET apps | Microsoft Docs

  9. 2022-3-28内部群每日三题-清辉PMP

    1.由于一直重复执行相同的任务,一个敏捷团队的士气低落.敏捷管理专业人士(主题专家 SME)应采取哪一项行动? A.增加团队的资源数量,协助主题专家完成任务. B.让团队成员执行其活动的价值流分析. ...

  10. Django 之 ORM2

    1. 多表操作 1.1 创建模型 实例:我们来假定下面这些概念,字段和关系 作者模型:一个作者有姓名和年龄. 作者详细模型:把作者的详情放到详情表,包含生日,手机号,家庭住址等信息.作者详情模型和作者 ...