当前位置:网站首页>【C#语言】具名类型和匿名类型
【C#语言】具名类型和匿名类型
2022-07-26 10:16:00 【文布斯】
匿名类型,经常用于LINQ查询的结果之中。
具名类型,它的对象创建表达式由三部分组成:new关键字,类名或构造函数,对象初始化语句。对象初始化语句在一组大括号内,包含了以逗号分隔的成员初始化列表。
匿名类型,它的对象创建表达式使用相同的形式,但是没有类名和构造函数。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 匿名类型
{
class Program
{
static void Main(string[] args)
{
//匿名类型的对象初始化语句
var Student = new { name = "张三", age = 16 };
Console.WriteLine("姓名:{0} , 年龄:{1}", Student.name, Student.age);
Console.Read();
}
}
}
如果编译器遇到了另一个具有相同的参数名,相同的推断类型,相同顺序的匿名类型,它会重新使用这个类型,并直接创建新的实例,不会创建新的匿名类型。
边栏推荐
- Wechat applet learning notes 1
- Uniapp "no mobile phone or simulator detected, please try again later" and uniapp custom components and communication
- Jpg to EPS
- The fourth week of summer vacation
- 论文笔记(SESSION-BASED RECOMMENDATIONS WITHRECURRENT NEURAL NETWORKS)
- Beginner of flask framework-04-flask blueprint and code separation
- 分布式网络通信框架:本地服务怎么发布成RPC服务
- Explain automatic packing and unpacking?
- Vectortilelayer replacement style
- INSTALL_FAILED_SHARED_USER_INCOMPATIBLE错误解决方式
猜你喜欢
Data communication foundation - layer 2 switching principle
Leetcode 504. Hex number
[qualcomm][network] QTI service analysis
万字详解“用知识图谱驱动企业业绩增长”
Employee information management system based on Web
点赞,《新程序员》电子书限时免费领啦!
30分钟彻底弄懂 synchronized 锁升级过程
Learning about opencv (2)
Basic usage of protobuf
Distributed network communication framework: how to publish local services into RPC services
随机推荐
在.NET 6.0中配置WebHostBuilder
Draw arrows with openlayer
【Halcon视觉】形态学膨胀
简单化构造函数的继承方法(二)- ES6中的class继承
Use of selectors
Yarn 'TSC' is not an internal or external command, nor is it a runnable program or batch file. The problem that the command cannot be found after installing the global package
Wechat H5 payment on WAP, for non wechat browsers
30分钟彻底弄懂 synchronized 锁升级过程
Production of a-modal drag function in antui
Rocky basic exercise -shell script 2
Sqoop [put it into practice 02] sqoop latest version full database import + data filtering + field type support description and example code (query parameter and field type forced conversion)
Okaleido生态核心权益OKA,尽在聚变Mining模式
服务发现原理分析与源码解读
句句解析js中的完美 / 缓冲运动框架(新手专用)
The problem of incomplete or partial display of the last recyclerview is solved
Employee information management system based on Web
Wechat applet learning notes 2
Use of pclint in vs2013
【Halcon视觉】阈值分割
Okaleido ecological core equity Oka, all in fusion mining mode