我可以为匿名类在C#中指定一个有意义的名字吗? [英] Can I specify a meaningful name for an anonymous class in C#?

查看:118
本文介绍了我可以为匿名类在C#中指定一个有意义的名字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们都知道,当我们创建一个匿名类是这样的:

  VAR员工=新{n = 5,名称=PRASHANT};
 

...在运行时,这将是类型:

 <> f__AnonymousType0< INT,字符串>
 

有没有什么办法可以指定一个有意义的名称,例如班?

解决方案

 公共类Employee {}
 

We all know that when we create an anonymous class like this:

var Employee = new { ID = 5, Name= "Prashant" };

...at run time it will be of type:

<>f__AnonymousType0<int,string>

Is there any way to specify a meaningful name to such classes?

解决方案

public class Employee {}

这篇关于我可以为匿名类在C#中指定一个有意义的名字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆