Prefix and postfix versions of the increment and decrement operators : Operators « Language Basics « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Language Basics » OperatorsScreenshots 
Prefix and postfix versions of the increment and decrement operators
Prefix and postfix versions of the increment and decrement operators
 
/*
Mastering Visual C# .NET
by Jason Price, Mike Gunderloy

Publisher: Sybex;
ISBN: 0782129110
*/

/*
  Example3_8.cs illustrates the use of
  prefix and postfix versions of the
  increment and decrement operators
*/

public class Example3_8
{

  public static void Main()
  {

    // postfix increment
    int length = 3;
    int newLength = length++;
    System.Console.WriteLine("Postfix increment example");
    System.Console.WriteLine("length = " + length);
    System.Console.WriteLine("newLength = " + newLength);

    // prefix increment
    length = 3;
    newLength = ++length;
    System.Console.WriteLine("Prefix increment example");
    System.Console.WriteLine("length = " + length);
    System.Console.WriteLine("newLength = " + newLength);

    // postfix decrement
    length = 3;
    newLength = length--;
    System.Console.WriteLine("Postfix decrement example");
    System.Console.WriteLine("length = " + length);
    System.Console.WriteLine("newLength = " + newLength);

    // prefix decrement
    length = 3;
    newLength = --length;
    System.Console.WriteLine("Prefix decrement example");
    System.Console.WriteLine("length = " + length);
    System.Console.WriteLine("newLength = " + newLength);

  }

}

           
         
  
Related examples in the same category
1.The + Operator Is Left Associative
2.Math Operators with int value
3.Demonstrate the difference between prefix postfix forms of ++Demonstrate the difference between prefix     postfix forms of ++
4.Demonstrate the relational and logical operatorsDemonstrate the relational and logical operators
5.Demonstrate the short-circuit operatorsDemonstrate the short-circuit operators
6.Side-effects can be importantSide-effects can be important
7.Prevent a division by zero using the ? 1Prevent a division by zero using the ? 1
8.Self incrementSelf increment
9.Self decreaseSelf decrease
10.Illustrates the use of the comparison operatorsIllustrates the use of the comparison operators
11.Illustrates the use of the Boolean logical operatorsIllustrates the use of the Boolean logical operators
12.Ternary operatorTernary operator
13.Illustrates the use of the ternary operatorIllustrates the use of the ternary operator
14.Illustrates the use of the arithmetic operatorsIllustrates the use of the arithmetic operators
15.Illustrates the use of the bitwise operatorsIllustrates the use of the bitwise operators
16.Illustrates the use of the shortcut operatorsIllustrates the use of the shortcut operators
17.Operator precedenceOperator precedence
18.Demonstrates compound assignment operatorsDemonstrates compound assignment operators
19.Relational Operators 3
20.Numeric Operators 3
21.Numeric Operators 1
22.Relational Operators
23.control the operator evaluation sequence
24.'logical and' and bitwise and
25.logical or and bitwise or
26.And Assignment
27.Or Assignment
28.Iff operator in C#
29.logical exclusive-or
30.Conditional operator and Math calculation
31.Add Assigment for both number and string value
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.