zoukankan      html  css  js  c++  java
  • C#3.0新特性之匿名类型

     

    示例代码如下,控制台应用程序:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace AnonymousTypeDemo
    {
        class Program
        {
            static void Main(string[] args)
            {
                var personWang = new
                {
                    Name = "张三",
                    Sex = true,
                    Age = 27
                };

                Console.WriteLine("Name属性:{0}",personWang.Name);
                Console.WriteLine("Sex属性:{0}", personWang.Sex);
                Console.WriteLine("Age属性:{0}", personWang.Age);

                var personWang1 = new
                {
                    Name = "张三",
                    Sex = true,
                    Age = 34            };

                var personWang2 = new
                {
                    Sex = true,
                    Name = "张三",
                    Age = 27
                };

                if (personWang.GetType() == personWang1.GetType())
                {
                    Console.WriteLine(@"personWang\personWang1两个对象是相同类型");
                }
                else
                {
                    Console.WriteLine(@"personWang\personWang1两个对象是不同类型");
                }

                if (personWang1.GetType() == personWang2.GetType())
                {
                    Console.WriteLine(@"personWang1\personWang2两个对象是相同类型");
                }
                else
                {
                    Console.WriteLine(@"personWang1\personWang2两个对象是不同类型");
                }

                if (personWang == personWang1)
                {
                    Console.WriteLine("两个对象是同一个对象");
                }
                else
                {
                    Console.WriteLine("两个对象不是同一个对象");
                }
            }
        }
    }

    尊重作者,转发请注明出处:http://www.cnblogs.com/minotmin
    谢谢阅读,有错请指出,不甚感激。

  • 相关阅读:
    几种常用的认证机制
    几种任务调度的 Java 实现方法与比较
    vue 安装教程
    JDK版本导致Unsupported major.minor version 52.0 error
    在SpringMVC框架下实现文件的 上传和 下载
    SpringMVC框架下实现JSON(类方法中回传数据到jsp页面,使用jQuery方法回传)
    SpringMVC框架下数据的增删改查,数据类型转换,数据格式化,数据校验,错误输入的消息回显
    SpringMVC框架的基础知识;
    hibernate的二级缓存
    hibernate检索方式(HQL 检索方式,QBC 检索方式,本地 SQL 检索方式)
  • 原文地址:https://www.cnblogs.com/minotmin/p/2701849.html
Copyright © 2011-2022 走看看