C # self-increment operator (+ +)

Source: Internet
Author: User

One, C # self-increment operator (+ +)

The increment operator (+ +) is the number of operands plus 1.

1. Prefix self-increment operator

The prefix increment operator is "Add 1 first, then use". The result of this operation is the value after the operand plus 1.

For example:

++x; Prefix self-increment operator

2. Postfix increment operator
The suffix increment operator is "first use, plus 1". The result of the operation is the value before the operand plus 1.

For example:

x + +; Postfix increment operator

Second, prompt

The self-increment operator (+ +) applies to numeric and enumeration types.

Iii. examples

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;

Namespace Test
{
    class program
    {
         static void Main (string[] args)
        {
            //C # auto-increment operator (+ +)-www.baike369.com
             int x = 0;
            Console.WriteLine ("The initial value of X is:" + x);
            Console.WriteLine ("(++x) x value is:" + (++x));
            Console.WriteLine ("After ++x, the value of X is:" + x);

x = 0;
The value of Console.WriteLine (x + +) is: "+ (x + +));
Console.WriteLine (after X + +, the value of × is: "+ x);
Console.ReadLine ();
}
}
}

Operation Result:

The initial value of X is: 0
The value of (++X) x is: 1
After ++x, the value of X is: 1
(x + +) The value is: 0
After X + +, the value is: 1

C # self-increment operator (+ +)

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.