Operators ++ : Prefix Postfix Operator « Operator « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » Operator » Prefix Postfix Operator 
3.3.10.Operators ++
using System;

  class Class1
  {
    [STAThread]
    static void Main(string[] args)
    {
      MyCar car = 5;

            forint i = 0; i < 20; ++i )
            {
                car++;
                Console.WriteLine"{0}", car.GetSpeed());
            }
    }
  }

  public class MyCar
  {
        private static int speed = 2;
        private const int maxSpeed = 200;
        
        public bool ChangeSpeed(int newSpeed)
        {
            ifnewSpeed > maxSpeed )
                return false;

            speed = newSpeed;

            return true;
        }

        public static MyCar operator ++MyCar car )
        {
            car.ChangeSpeed(++speed);
            return car;
        }

        public static implicit operator MyCarint from )
        {
            MyCar car = new MyCar();
            car.ChangeSpeedfrom );
            return car;
        }

        public int GetSpeed()
        {
            return speed;
        }
  }
3.3.Prefix Postfix Operator
3.3.1.Increment and Decrement
3.3.2.Pre And Post Increment
3.3.3.The difference between prefix and postfix forms of ++
3.3.4.postfix increment
3.3.5.prefix increment
3.3.6.postfix decrement
3.3.7.prefix decrement
3.3.8.Using the Post-Increment Operator
3.3.9.Using the Pre-Increment Operator
3.3.10.Operators ++
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.