代码参考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. ReactJS单页面应用之项目搭建

    初衷 因接手的项目前端采用reactjs+antd,为把控项目中的各个细节,所以想做一些整理,以免后期遗忘. 创建及启动项目 # 全局安装create-react-app # 如果曾经安装过,可先移除 ...

  2. HOW TO RENDER TO A TEXTURE ARRAY IN UNITY

    http://xdpixel.com/how-to-render-to-a-texture-array-in-unity/

  3. PyMySQL更新

    title: PyMySQL更新 author: 杨晓东 permalink: PyMySQL更新 date: 2021-10-02 11:27:04 categories: - 投篮 tags: - ...

  4. 1.win10安装centos虚拟机并设置允许远程

    一.下载并安装 打开如下连接,下载VMware和CentOS7镜像安装好虚拟机 http://t.zoukankan.com/onlymate-p-9837651.html这个链接的镜像是7.0的,我 ...

  5. vscode 部分替换(正则替换)

    1. 数字 \d{n} 2. 数字和字母 [A-Za-z0-9]{n} 常用运算符与表达式 ^ 开始 () 域段 [] 包含,默认是一个字符长度 [^] 不包含,默认是一个字符长度 {n,m} 匹配长 ...

  6. css盒子在不同浏览器下的差异

    标准盒子模型 盒子模型的氛围包括四个部分:margin,border,padding,content 标准盒子模型的content不包括其他内容,只有width跟height部分     conten ...

  7. get与post区别,https协议的通信机制

    get与post区别 幂等的的意思就是一个操作不会修改状态信息,并且每次操作的时候都返回同样的结果.即:做多次提交和做一次的对服务器效果是一样 的. 方法 用法 是否能修改服务器数据 幂等 安全 入参 ...

  8. Burp Suite入门

    Burpsuite Burp Suite是一个Web应用程序集成攻击平台,它包含了一系列burp工具,这些工具之间有大量接口可以互相通信,这样设计的目的是为了促进和提高整个攻击的效率.平台中所有工具共 ...

  9. 记录[极客大挑战2019]http

    打开网站源码--找到secret.php,要从www.Sycsecret.com访问--加上Referer 注:HTTP Referer是header的一部分,当浏览器发送请求的时候带上Referer ...

  10. Delphi实现Windows的气泡提示样式

    其实也不复杂,主要使用到shellAPI下的TNotifyIconData这个结构体: typedef struct _NOTIFYICONDATA { DWORD cbSize; //结构体的大小, ...