![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.GetDefaultMembers() Method in C#
The Type.GetDefaultMembers() method in C# is used to search for the members defined for the current Type whose DefaultMemberAttribute is set.
Syntax
public virtual System.Reflection.MemberInfo[] GetDefaultMembers ();
Let us now see an example to implement the Type.GetDefaultMembers() method −
Example
using System; using System.Reflection; [DefaultMemberAttribute("subject")] public class Demo { public static void Main(){ Type t = typeof(Demo); MemberInfo[] member = t.GetDefaultMembers(); if (member.Length != 0){ for (int i = 0; i < member.Length; i++) Console.WriteLine("{0}", member[i]); } else { Console.WriteLine("Default Member isn't there!"); } } public void Name(String str) {} public String subject{ get{ return "Mathematics"; } } }
Output
This will produce the following output −
System.String subject
Let us now see another example to implement the Type.GetDefaultMembers() method −
Example
using System; using System.Reflection; [DefaultMemberAttribute("rank")] public class Demo { public static void Main(){ Type t = typeof(Demo); MemberInfo[] member = t.GetDefaultMembers(); if (member.Length != 0){ for (int i = 0; i < member.Length; i++) Console.WriteLine("{0}", member[i]); } else { Console.WriteLine("Default Member isn't there!"); } } public void Name(String str) {} public int rank{ get{ return 5; } } }
Output
This will produce the following output −
Int32 rank
Advertisements