Tuesday, July 19, 2016

c# programming tutorial - Basic Operator Overloading

C# Object-Oriented Programming tutorial depicts a third over-overloading method. By over-overloading the usefulness of operators  the operation of the standard operators including  (+) and      (-)can be characterized for new classes.  

  • Operator Overloading

So far in this instructional exercise we have made classes to describe real-world objects complete with their suitable strategies and properties.
 These objects have not required the implementation of arithmetic operators as this type of functionality was not proper. In this article, we will create a class that does supports arithmetic operations using operator overloading.

Operator over-burdening is simply the way of adding operator functionality to a class. This permits you to define precisely how the operator acts when utilized with your class and other data types. This can be standard uses, for example, the capacity to include the estimations of two vectors, more complicated for multiplying matrices or non-arithmetic-functions, for example, utilizing the + operator to add another thing to an item to collection or combine the contents of two arrays and Multiple overloaded versions of operators may likewise be made to give different functionality according by the data types being processed, in a similar manner to the varying signatures of technique overloading
In this article we will make a new class to represent a two-dimensional vector with X and Y properties.To start, make a new console application named "VectorDemo" and include a new class document named "Vector". Add the following code to the new class to make the properties and a basic constructor:

private int _x,_y;
public Vector(int x, int y) { _x = x; _y = y; }
public int X
{
get{return _x; }
set{_x = value; }
}
public int Y
{
get{ return _y; }
set{ _y = value; }
}


Binary Operator Overloading

The first type of operator to consider is the binary operator, so named because they require two values to work with. These include the s simple arithmetic operators, for example, +, - , *,/and %. To declare a binary operator, the following syntax is utilized:


public static result-type operator binary-operator (
op-type operand,
op-type2 operand2
)
The result-type defines the data type or class that is returned as the result of utilizing the operator. Generally this will be the same type as the class that it is being defined within.However that necessity not be the case and it is perfectly valid to return data of a different type 

The operator keyword is added to say the compiler that the following binary operator symbol is an operator rather than a normal method. This operator will then procedure the two operand parameters, each prefixed with its data type  op-type and op-type2. As op-type and op-type2 one of these operands must be the similar type as the containing class.


learn about c programming

Read More

c++

Read More

Monday, July 18, 2016

Java programming

Read More

Javascript

Read More

PHP programming

Read More