C # and VB.net type related data collation

Source: Internet
Author: User
Tags instance method integer

C # and VB.net have some and type-related methods and keywords, beginners just start to understand may be a little confusing, here to tidy up, hoping to help beginners. If you have something to add, you are welcome to reply.

1.GetType

(1) Object.GetType ()

This method is a method for all objects, and the explanation in MSDN is "get the Type of the current instance." ”。 The return value of the method is an instance of the System.Type type, representing the exact run-time type of the current instance.

For example:

C#:

int number = 3;
System.Type t = number.GetType();
Console.WriteLine(t.FullName); //输出:System.Int32

VB.net:

Dim number as Integer = 3
Dim t As System.Type = number.GetType()
Console.WriteLine(t.FullName) '输出:System.Int32

(2) Vb. GetType method in net

Refer to the explanation in MSDN: Returns a type object of the specified types. Type objects provide information about types, such as properties of types, methods, and events.

Usage: GetType (TypeName), where TypeName is the name of the type that needs to get its information.

For example:

Dim t As System.Type = GetType(Integer)
Console.WriteLine(t.FullName) '输出:System.Int32

(3) Type.GetType Series Method

There are 4 GetType methods in the System.Type type, where the GetType () with no parameters is an instance method that inherits from object, and the other three are static methods (C # is static, VB.) NET is shared). The example method does not need to introduce, is Object.GetType (). A static method is to get System.Type by a string of type names. The explanation in MSDN has one big piece, and here's a simple example:

C#:

System.Type t = Type.GetType("System.Int32");
Console.WriteLine(t.FullName); //输出:System.Int32

vb.net

Dim t As System.Type = Type.GetType("System.Int32");
Console.WriteLine(t.FullName) '输出:System.Int32

Note that the type name here must be the full name of the containing namespace, that is, the System.Type fullname, not the type name in C # or vb.net, such as "int" in C # or "Integer" in vb.net

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.