![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Type.GetFields() Method in C#
The Type.GetFields() method in C# is used to get the fields of the current Type.
Syntax
Following is the syntax −
public System.Reflection.FieldInfo[] GetFields ();
Example
Let us now see an example to implement the Type.GetFields() method −
using System; using System.Reflection; public class Demo { public static void Main(){ Type type = typeof(System.String); FieldInfo [] fields = type.GetFields(BindingFlags.Static | BindingFlags.NonPublic); Console.WriteLine ("Following are the non-public fields="); foreach (FieldInfo myField in fields){ Console.WriteLine(myField.ToString()); } } }
Output
This will produce the following output −
Following are the non-public fields= Int32 TrimHead Int32 TrimTail Int32 TrimBoth Int32 charPtrAlignConst Int32 alignConst
Example
Let us now see another example to implement the Type.GetFields() method −
using System; using System.Reflection; public class Demo { public static void Main(){ Type type = typeof(System.Char); FieldInfo [] fields = type.GetFields(BindingFlags.Static | BindingFlags.NonPublic); Console.WriteLine ("
Following are the non-public fields="); foreach (FieldInfo myField in fields){ Console.WriteLine(myField.ToString()); } } }
Output
This will produce the following output −
Following are the non-public fields= Byte[] categoryForLatin1 Int32 UNICODE_PLANE00_END Int32 UNICODE_PLANE01_START Int32 UNICODE_PLANE16_END Int32 HIGH_SURROGATE_START Int32 LOW_SURROGATE_END
Advertisements