ASP. NET learning notes (15th)-basic common knowledge

Source: Internet
Author: User

I. Differences between public variables and attributes
1. attributes can be read and written through get set, but variables cannot;

2. attributes can be assigned values, but variables cannot;

3. in reality, when we bind data to an object, attributes can be bound normally, but variables cannot. Therefore, when we need to set a value in the class to public, use attributes instead of variables;


Ii. Differences between parameter modifiers Params, out, and ref
1. After the params keyword, other parameters are not allowed, and only one params is allowed in the method declaration. A variable parameter can be set for the method.

 

2. out

All the modifications made to the out parameter in the method are reflected in this variable.

You do not need to initialize the variable to be used as a parameter, because it will be cleared after entering the method;
Attribute is not a variable and cannot be passed as an out Parameter


If the two methods are different only in the usage of out, the overload will occur.

3. All changes made to the ref-modified parameters in the method are reflected in this variable.
The variable modified by ref must be initialized because only an address is passed.

Iii. Differences between values and reference types

 
By: dxh_0829

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.