当前位置:网站首页>【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();
}
}
}
如果编译器遇到了另一个具有相同的参数名,相同的推断类型,相同顺序的匿名类型,它会重新使用这个类型,并直接创建新的实例,不会创建新的匿名类型。
边栏推荐
- Interview shock 68: why does TCP need three handshakes?
- [Qualcomm][Network] qti服务分析
- 时间序列异常检测
- Encapsulation of tabbarcontroller
- Network related journals and conferences in CS
- PHP one-time request lifecycle
- Android greendao数据库的使用
- 面试突击68:为什么 TCP 需要 3 次握手?
- 点赞,《新程序员》电子书限时免费领啦!
- Study notes of the second week of sophomore year
猜你喜欢

PMM (percona monitoring and management) installation record

数通基础-STP原理

万字详解“用知识图谱驱动企业业绩增长”

Data communication foundation - layer 2 switching principle

服务发现原理分析与源码解读

On the compilation of student management system of C language course (simple version)

Leetcode 504. Hex number

How to write a million reading article

Mysql5.7.25 master-slave replication (one-way)

数据库的复习--3.SQL语言
随机推荐
All codes of Tetris
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)
面试第二家公司的面试题及答案(二)
Usage of the formatter attribute of El table
【Halcon视觉】图像的傅里叶变换
【有奖提问】向图灵奖得主、贝叶斯网络之父 Judea Pearl 提问啦
【Halcon视觉】形态学膨胀
Wechat applet learning notes 2
The fourth week of summer vacation
Azkaban [basic knowledge 01] core concepts + features +web interface + Architecture +job type (you can get started with Azkaban workflow scheduling system in one article)
Basic usage of protobuf
Principle analysis and source code interpretation of service discovery
The use of MySQL in nodejs
Distributed network communication framework: how to publish local services into RPC services
Interview shock 68: why does TCP need three handshakes?
Server memory failure prediction can actually do this!
Necessary for beginners: debug breakpoint debugging skills in idea and common breakpoint skills
Docker configuring MySQL Cluster
Uniapp "no mobile phone or simulator detected, please try again later" and uniapp custom components and communication
Using undertow, Nacos offline logout delay after service stop