C# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó


Diễn đàn chia sẻ kiến thức, kinh nghiệm về IT và cuộc sống!
 
Trang ChínhGalleryTìm kiếmLatest imagesĐăng kýĐăng Nhập
Top posters
Sakura (1124)
C# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Vote_lcapC# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Voting_barC# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Vote_rcap 
hotboy (705)
C# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Vote_lcapC# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Voting_barC# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Vote_rcap 
Già Làng (373)
C# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Vote_lcapC# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Voting_barC# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Vote_rcap 
con_ca_nho90 (289)
C# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Vote_lcapC# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Voting_barC# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Vote_rcap 
that_true (154)
C# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Vote_lcapC# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Voting_barC# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Vote_rcap 
theanhkkt (143)
C# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Vote_lcapC# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Voting_barC# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Vote_rcap 
phamay (137)
C# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Vote_lcapC# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Voting_barC# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Vote_rcap 
lovelonelyman (134)
C# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Vote_lcapC# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Voting_barC# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Vote_rcap 
o0ovioletstaro0o (128)
C# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Vote_lcapC# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Voting_barC# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Vote_rcap 
stevenhung (122)
C# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Vote_lcapC# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Voting_barC# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Vote_rcap 
Âm - Dương lịch
Clock
Logo
11TH02 Pro!
Liên kết
Tin tức 60s
Tin công nghệ
Thời sự 24h
Game Moblie

Share
 

 C# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó

Xem chủ đề cũ hơn Xem chủ đề mới hơn Go down 
Tác giảThông điệp
Sakura

C# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Stars7
Sakura

Thú CƯng : C# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó I-hate-Cats-icon
Nam Scorpio

Số bài viết : 1124
Điểm : 1688
Được cảm ơn : 35
Ngày sinh : 03/11/1990
Tham gia ngày : 16/03/2010
Tuổi : 33
Đến từ : Bình Dương
Ngề nghiệp : IT Student

C# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Empty
Bài gửiTiêu đề: C# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó   C# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó I_icon_minitime23/7/2010, 17:44

Đây là phần tóm tắt về Overload các toán tử trong C#, rất hay và dễ hiểu, các bạn nên tập đọc và viết code bằng Tiếng Anh thì sẽ nhanh lên tay hơn đó. 2 trong 1 là vì vừa học Ngôn ngữ lập trình và vừa học luôn AVCN. kakak!
Trích:
All unary and binary operators have pre-defined implementations, that are automatically available in any expressions. In addition to this pre-defined implementations, user defined implementations can also be introduced in C#. The mechanism of giving a special meaning to a standard C# operator with respect to a user defined data type such as classes or structures is known as operator overloading. Remember that it is not possible to overload all operators in C#. The following table shows the operators and their overloadability in C#.
Operators Overloadability
+, -, *, /, %, &, |, <<, >> All C# binary operators can be overloaded.
+, -, !, ~, ++, –, true, false All C# unary operators can be overloaded.
==, !=, <, >, <= , >= All relational operators can be overloaded,
but only as pairs.
&&, || They can’t be overloaded
() (Conversion operator) They can’t be overloaded
+=, -=, *=, /=, %= These compound assignment operators can be
overloaded. But in C#, these operators are
automatically overloaded when the respective
binary operator is overloaded.
=, . , ?:, ->, new, is, as, size of These operators can’t be overloaded
In C#, a special function called operator function is used for overloading purpose. These special function or method must be public and static. They can take only value arguments.The ref and out parameters are not allowed as arguments to operator functions. The general form of an operator function is as follows.
public static return_type operator op (argument list)
Where the op is the operator to be overloaded and operator is the required keyword. For overloading the unary operators, there is only one argument and for overloading a binary operator there are two arguments. Remember that at least one of the arguments must be a user-defined type such as class or struct type.
Overloading Unary Operators – the general form of operator function for unary operators is as follows.public static return_type operator op (Type t){// Statements}Where Type must be a class or struct.The return type can be any type except void for unary operators like +,~, ! and dot (.). but the return type must be the type of ‘Type’ for ++and o remember that the true and false operators can be overloaded only as pairs. The compilation error occurs if a class declares one of these operators without declaring the other.
The following program overloads the unary – operator inside the class Complex
// Unary operator overloading
// Author: [You must be registered and logged in to see this link.]
Spoiler:
Overloading Binary Operators
An overloaded binary operator must take two arguments, at least one of them must be of the type class or struct, inwhich the operation is defined. But overloaded binary operators can return any value except the type void. The general form of a overloaded binary operator is as follows.
Spoiler:
The binary operators such as = =, ! =, <,>, < =, > = can be overloaded only as pairs. Remember that when a binary arithmetic operator is overloaded, corresponding assignment operators also get overloaded automatically. For example if we overload + operator, it implicitly overloads the + = operator also.
Summary
1.The user defined operator declarations can’t modify the syntax, precedence or associativity of an operator. For example, a + operator is always a binary operator having a predefined precedence and an associativity of left to right.
2.User defined operator implementations are given preference over predefined implementations.
3.Operator overload methods can’t return void.
4.The operator overload methods can be overloaded just like any other methods in C#. The overloaded methods should differ in their type of arguments and/or number of arguments and/or order of arguments.Remember that in this case also the return type is not considered as part of the method signature.
Conclusion
The operator overloading is one of the key concepts of C# and are very interesting aspects of the language. I’ve given you enough information to use operator overloading in your code and shown you some examples. The feedback is always welcome. Feel free to contact me at [You must be registered and logged in to see this link.]
Về Đầu Trang Go down
hotboy

C# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Stars7
hotboy

Thú CƯng : C# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Hippopotamus-icon
Nam Aries

Số bài viết : 705
Điểm : 1043
Được cảm ơn : 9
Ngày sinh : 21/03/1990
Tham gia ngày : 13/05/2010
Tuổi : 34
Đến từ : BDU

C# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó Empty
Bài gửiTiêu đề: Re: C# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó   C# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó I_icon_minitime23/7/2010, 23:04

cái này cũng hay đấy,thích nhất là 1 công đôi việc.thank 1 phát nào
Về Đầu Trang Go down
 

C# Operator Overloading - Chịu Khó Đọc 2 Trong 1 Đó

Xem chủ đề cũ hơn Xem chủ đề mới hơn Về Đầu Trang 
Trang 1 trong tổng số 1 trang

 Similar topics

-
» Những thay đổi quan trọng trong Windows 7 Service Pack 1
» 10 điều khó chịu nhất đối với lập trình viên
» 8 Lần Nói Dối Trong Cuộc Đời Người Mẹ !
» Một số hàm xử lý chuỗi trong sql
» Một số hàm "độc" trong C# Consle

Permissions in this forum:Bạn không có quyền trả lời bài viết
IT World! :: HỌC TẬP :: Học Kỳ IV :: Lập Trình Hướng Dối Tượng(OOP)-