skip to main
|
skip to sidebar
Operator overloading in C Sharp
- The mechanism of providing a special meaning to the standard C sharp operator with respect to a user defined data type is known as operator overloading. That means, Operator overloading allows you to implement types that behave like the built-in types when using operators.
- Operator overloading allows programmers to build types which feel as natural to use as simple types.
- During Operator overloading always give public static access specifiers.
- C sharp offers provide the functionality for to create structure and class interfaces that are easier and more intuitive is referred as operator overloading.
- Operator Overloading should return a CLS type and not void.
- Operator Overloading is pretty useful concept derived from C++ by C sharp.
- Be sure to use operators in a way that is natural and understandable for the type.
- The syntax for implementing operators is much like a static method, but includes the operator keyword and the operator symbol in place of an identifier.
public static return_type operator operator(arguments)
{
//code
}
Operator overloading Rules
- C# enforces certain rules when you overload operators. One rule is that you must implement the operator overload in the type that will use it. This is sensible because it makes the type self-contained.
- The relational operators are always overloaded in matching pairs (operators) only. For example, if you overload ==, you must also implement !=. The same goes for <= and >=.
- When you implement an operator, its compound operator works also like +=.
0 comments :
Post a Comment