The difference between C # typeof and GetType ()

Source: Internet
Author: User

Description of the type class in C #: Https://msdn.microsoft.com/zh-cn/library/system.type (vs.80). aspx

Any object in C # has the GetType () method, and its function is the same as typeof (), which returns the type of the current object of type. X in typeof (X), must be a specific class name, type name, etc., cannot be a variable name, GetType () is a method of the base class System.Object, so only after an instance is established can it be called

The difference between the two:

1, typeof is the operator but the method

2, GetType () is a method of the base class System.Object, so only after an instance is established can it be called (after initialization)

3, typeof parameters can only be int,string,string, custom type, and cannot be an instance

4, GetType (), and typeof all return System.Type references.

5, TypeOf (): Get a class type

6. GetType (): Gets the type of an instance of class

The difference between C # typeof and GetType ()

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.