C# Type GetMember(String)

Description

Type GetMember(String) searches for the public members with the specified name.

Syntax

Type.GetMember(String) has the following syntax.


public MemberInfo[] GetMember(
  string name
)

Parameters

Type.GetMember(String) has the following parameters.

  • name - The string containing the name of the public members to get.

Returns

Type.GetMember(String) method returns

Example

The following example displays all the members of the String class that start with the letter C.


/*  w  ww .  j av a  2 s .  c om*/
using System;
using System.Security;
using System.Reflection;

public class MyMemberSample 
{
    public static void Main()
    {
        String myString = "GetMember_String";

        Type myType = myString.GetType();
        MemberInfo[] myMembers = myType.GetMember("C*");
        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.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version