全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using Instance1;using System.Collections;namespace Instance class Program static void Main(string args) /Instance1.gram.Divide() /var result = Instance1.gram.Divide(5, 2); /Console.WriteLine(result of division: 0 / reminder1, result.Item1, result.Item2); /超过八个参数的Tuple类定义,使用模板参数TRest /Instance1.Person() var janet = new Instance1.Person FirstName = Janet, LastName = Jackson ; Person persons1 = new Person FirstName = Michael, LastName = Jackson , janet ; Person persons2 = new Person FirstName = Michael, LastName = Jacson , janet ; if (persons1 != persons2) Console.WriteLine(not the same regerence); if (persons1 as IStructuralEquatable).Equals(persons2,EqualityComparer.Default) /as强制转换为IStructuralEquatable接口 Console.WriteLine(the same content); if (persons1 as IStructuralEquatable).Equals(persons2,EqualityComparer.Default) /EqualityComparer(T)检查T是否实现IEquatable接口并调用IEquatable.Equals()方法,没有继承接口则调用object的Equals()方法 Console.WriteLine(the same content); /对元组执行相同的操作 var t1 = Tuple.Create(1, tuple); var t2 = Tuple.Create(1, stephanie); if(t1 != t2) /因为引用两个不同不同对象所以true Console.WriteLine(not the reference to the tuple); if (t1.Equals(t2) /因为值一样,所以返回true Console.WriteLine(tbe same contrnt); /使用自定义类给Tuple类的方法传递一个新实例,要调用两次TupleComparer,来检查是否相等 /if (t1.Equals(t2, new TupleComparer() / Console.WriteLine(equals using TupleComparer); Console.ReadKey(); return; namespace Instance1 public class gram public static Tuple Divide(int dividend,int divisor) int result = dividend / divisor; int reminder = dividend % divisor; return Tuple.Create (result,reminder); /元组合并不同类型的对象 public class Person:IEquatable public int Id get; set; public string FirstName get; set; public string LastName get; set; public override string ToString() return String.Format(012,Id,FirstName,LastName); public override bool Equals(object obj) if (obj = null) throw new ArgumentNullException(obj); return Equals(obj as Person); public override int GetHashCode() return Id.GetHashCode(); public bool Equals(Person other) if (other = null) throw new ArgumentNullException(other); return this.Id = other.Id & this.FirstName = other.FirstName & this.LastName = other.LastName; /创建一个自定义的IEqualityComparer class TupleComparer:IEqualityComparer public new bool Equals(object x,object y) return x.Equals(y); public int GetH
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 工程项目挂靠协议书
- 部编版(25秋)小学二年级上册道德与法治教案全册
- 2024-2025学年辽宁省沈阳市于洪区七年级(下)期末英语试卷(含答案解析)
- 2025年及未来5年市场数据中国冷光孔式手术无影灯行业全景评估及投资规划建议报告
- 2026年建筑工程技术资料管理合同
- 复句语病类型
- 销售年终个人工作总结(集锦15篇)
- 犬猫临床生化指标
- 2026年公共营养师(初级膳食指导)自测试题及答案
- 5G支持的海量物联设备管理-洞察与解读
- 物理因子治疗冲击波疗法
- 2025金沙辅警考试真题
- 药学三基考试试题(带答案)
- 2025年6月黑吉辽蒙高考地理真题完全解读
- 宾馆消防业管理制度
- 传媒策划试题及答案模板
- 测量实训室管理制度
- 煤矿工人井下封闭心理建设
- 国家职业标准-电力电气设备安装工 (试行) (2024 年版)
- 公司质量红线管理制度
- 租女友过年协议书
评论
0/150
提交评论