CSharp Keyword -- Type

Source: Internet
Author: User

C #PassedTypeAttackers can access any data type.
1. There are three methods to obtain a Type reference of a given Type:
A. Use the typeof operator, such as Typet = typeof (int );
B. Use the GetType () method, such as int I; Type t = I. GetType ();
C. UseTypeStatic Method GetType (), such as Type t = Type. GetType ("System. Double ");
2. Type attributes:
Name: Name of the data type;
FullName: a fully qualified name for the data type, including the namespace;
Namespace: a data-type Namespace;
BaseType: basic type;
UnderlyingSystemType: ing type;
3. Type method:
GetMethod (): returns information about a method;
GetMethods (): returns information about all methods.
TestType. cs:

TestTypeView.cs: 
Using System;
Using System. Text;
Using System. Windows. Forms;
Using System. Reflection;

Namespace Magci. Test. Reflection
{
Public class TestTypeView
{
Public static StringBuilder OutputText = new StringBuilder ();

Public static void Main ()
{
Type t = typeof (double );
AnalyzeType (t );
MessageBox. Show (OutputText. ToString ());
}

Public static void AnalyzeType (Type t)
{
// Data type name
OutputText. Append ("\ nType Name:" + t. Name );
// A fully qualified name for the data type, including the namespace
OutputText. Append ("\ nFull Name:" + t. FullName );
// Data type namespace
OutputText. Append ("\ nNamespace:" + t. Namespace );

// Direct basic type
Type tBase = t. BaseType;
If (tBase! = Null)
{
OutputText. Append ("\ nBase Type:" + tBase. Name );
}

// Ing type
Type tUnderlyingSystem = t. UnderlyingSystemType;
If (tUnderlyingSystem! = Null)
{
OutputText. Append ("\ nUnderlyingSystem Type:" + tUnderlyingSystem. Name );
}

// All public methods
OutputText. Append ("\ n \ nPublic members :");
MemberInfo [] methods = t. GetMethods ();
Foreach (MemberInfo method in methods)
{
OutputText. Append ("\ n" + method. DeclaringType + "" + method. MemberType + "" + method. Name );
}
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.