Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the Anonymous Type structure of C #?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "what is the Anonymous Type structure of C#". In the daily operation, I believe that many people have doubts about the Anonymous Type structure of C#. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "what is the Anonymous Type structure of C#"! Next, please follow the editor to study!

C # Anonymous Type is only a new feature of C # 3.0, not that Anonymous Type is a new feature of .NET Framework 3.5. This is because Anonymous Type is only a new feature of the .NET Programming Language and the corresponding Compiler. For .NET Framework 3.5, it doesn't see any difference. In other words, for Anonymous Type and regular Named Type, there is no fundamental difference between them for CLR.

For a simple piece of code like this:

Public sealed class f__AnonymousType0

{

/ / Properties

Public j__AnonymousTypeTypeParameter1ID {get; set;}

Public j__AnonymousTypeTypeParameter2 Name {get; set;}

/ / Fields

Private j__AnonymousTypeTypeParameter1 i__AnonymousTypeField3

Private j__AnonymousTypeTypeParameter2 i__AnonymousTypeField4

}

< >

J__Anonymous Type Type Parameter1 and

< >

The two Generic Type of j__Anonymous Type Type Parameter2 represent the types of ID and Name that I defined in {}. Through this structure, we find that its definition is no different from the general Generic Type.

To further understand what kind of C # Anonymous Type is generated, let's use IL DASM to look at the general structure of the generated Anonymous Type at the IL level:

To make a comparison, here is the structure of Named Employee Type in IL DASM that we initially defined:

At this point, the study of "what is the Anonymous Type structure of C#" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report