C# Type GetMember(String, BindingFlags)
Description
Type GetMember(String, BindingFlags)
searches for
the specified members, using the specified binding constraints.
Syntax
Type.GetMember(String, BindingFlags)
has the following syntax.
public virtual MemberInfo[] GetMember(
string name,
BindingFlags bindingAttr
)
Parameters
Type.GetMember(String, BindingFlags)
has the following parameters.
name
- The string containing the name of the members to get.bindingAttr
- A bitmask comprised of one or more BindingFlags that specify how the search is conducted.bindingAttr
- -or-bindingAttr
- Zero, to return an empty array.
Returns
Type.GetMember(String, BindingFlags)
method returns
Example
The following example displays all the public static members of the myString class that start with the letter C.
using System;// ww w .j av a 2 s.c om
using System.Reflection;
public class MainClass{
public static void Main(String[] argv){
String myString = "java2s.com";
Type myType = myString.GetType();
MemberInfo[] myMembers = myType.GetMember("C*",BindingFlags.Public |BindingFlags.Static);
if(myMembers.Length > 0)
{
Console.WriteLine(myType);
for(int index=0; index < myMembers.Length; index++)
Console.WriteLine("Member {0}: {1}", index + 1, myMembers[index].ToString());
}
else
Console.WriteLine("No members match the search criteria.");
}
}
The code above generates the following result.