The resolution type is followed by question marks and double question marks. The resolution type is followed by question marks.

Source: Internet
Author: User

The resolution type is followed by question marks and double question marks. The resolution type is followed by question marks.

In the variable definition, the type is followed by a question mark, indicating that the data type is NullAble. When you set an initial value for a variable, assign null to the variable (int type) instead of 0!

Example:

Int? I = 3 is equivalent to Nullable <int> I = new Nullable <int> (3 );

Int? Is another method of writing generic Nullable <int>.

When defining a method, null values can be passed:


Public void AddUser (string name, string password, int? Role) {// content omitted ...} // use AddUser ("Xiao Ming", "123456", null); // The default value of null is unaudited user AddUser ("Xiao Wang", "123456", 1 ); // Postmaster AddUser ("why?", "123456", 2); // common user view plaincopy to clipboardprint? Public void AddUser (string name, string password, int? Role) {// content omitted ...} // use AddUser ("Xiao Ming", "123456", null); // The default value of null is unaudited user AddUser ("Xiao Wang", "123456", 1 ); // Postmaster AddUser ("why?", "123456", 2); // common user

 

2. There are two question marks after the type in the variable definition. They are used to determine and assign values. First, they determine whether the current variable is null. If yes, they can be assigned a new value. Otherwise, they will be skipped! What does it mean to take the assigned value ?? On the left, if the left is null, the assigned value is used ?? On the right.

Example: page ?? 0 indicates that when page is null, the value on the right is 0.

Recommended: http://www.cnblogs.com/roucheng/p/3562327.html

Related Article

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.