当前位置:网站首页>【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();
}
}
}
如果编译器遇到了另一个具有相同的参数名,相同的推断类型,相同顺序的匿名类型,它会重新使用这个类型,并直接创建新的实例,不会创建新的匿名类型。
边栏推荐
- Learning about opencv (1)
- C language course design Tetris (Part 1)
- Self encapsulated database dbutils universal template
- Tower of Hanoi II | tower of Hanoi 4 columns
- Vs2019 configuring opencv
- Opencv image processing
- Time series anomaly detection
- 在.NET 6.0中配置WebHostBuilder
- AirTest
- Usage of the formatter attribute of El table
猜你喜欢

服务器内存故障预测居然可以这样做!

Meeting OA project (III) -- my meeting (meeting seating and submission for approval)

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

数通基础-STP原理

Learning about opencv (2)

Data communication foundation TCPIP reference model
![Uniapp common error [wxml file compilation error]./pages/home/home Wxml and using MySQL front provided by phpstudy to establish an independent MySQL database and a detailed tutorial for independent da](/img/21/5dceab9815b503f0b62d26a430d7eb.png)
Uniapp common error [wxml file compilation error]./pages/home/home Wxml and using MySQL front provided by phpstudy to establish an independent MySQL database and a detailed tutorial for independent da

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

数通基础-二层交换原理

面试突击68:为什么 TCP 需要 3 次握手?
随机推荐
面试突击68:为什么 TCP 需要 3 次握手?
论文笔记(SESSION-BASED RECOMMENDATIONS WITHRECURRENT NEURAL NETWORKS)
Mqtt x cli officially released: powerful and easy-to-use mqtt 5.0 command line tool
Keeping alive to realize MySQL automatic failover
Data communication foundation - layer 2 switching principle
How to use Gmail to pick up / send mail on Foxmail
Using undertow, Nacos offline logout delay after service stop
Explain automatic packing and unpacking?
【Halcon视觉】形态学腐蚀
数通基础-Telnet远程管理设备
Vs2019 configuring opencv
El table implements adding / deleting rows, and a parameter changes accordingly
Employee information management system based on Web
Learning about tensorflow (I)
Under win10 64 bit, matlab fails to configure notebook
Show default image when wechat applet image cannot be displayed
Cloud native (36) | introduction and installation of harbor in kubernetes
[fluorescent character effect]
Data communication foundation telnet remote management equipment
Map key not configured and uniapp routing configuration and jump are reported by the uniapp < map >< /map > component