Notice
Recent Posts
Recent Comments
Link
- Today
- Total
반응형
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
Tags
- Bucket
- C#
- group by
- 올림
- 데이터테이블
- mssql
- 소수점
- 대량 insert
- 문자열 찾기
- 날짜 변환 형식
- lastIndexOf
- 이행은 이미
- PostgreSQL
- DataTable Copy
- 버림
- datatable 행 제거
- 다른 테이블에 속해있습니다
- cursor
- DataTable Merge
- MS-SQL
- indeof
- 날짜 변환
- 데이터테이블 합치기
- contains
- datatable 컬럼 제거
- DataTable
- merge
- Elasticsearch
- 소수점 자르기
- Column
Archives
노트
[C#] 연산자 오버로딩(operator) 본문
반응형
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
public class OverloadingTest
{
public int A { get; set; }
public int B { get; set; }
public OverloadingTest(int \_a, int \_b)
{
this.A = \_a;
this.B = \_b;
}
public static OverloadingTest operator +(OverloadingTest o1, OverloadingTest o2)
{
return new OverloadingTest(o1.A + o1.B, o2.A + o2.B);
}
public static OverloadingTest operator -(OverloadingTest o1, OverloadingTest o2)
=> new OverloadingTest(o1.A, o2.B);
public override string ToString()
{
return string.Format("A : {0}, B : {1}", A, B);
}
}
class Program
{
static void Main(string\[\] args)
{
OverloadingTest over1 = new OverloadingTest(1, 2);
OverloadingTest over2 = new OverloadingTest(10, 20);
Console.WriteLine((over1 + over2).ToString()); // output - A : 3, B : 30
Console.WriteLine((over1 - over2).ToString()); // output - A : 1, B : 20
}
}
|
cs |
미리정의된 연산자(+,-,* 등등)를 오버로딩 할 수있다.
즉 해당 연산자에 대해 의미를 다시 부여하는 것이다.
출처 : https://docs.microsoft.com/ko-kr/dotnet/csharp/language-reference/operators/operator-overloading
반응형
'ㄱㅂ > C#' 카테고리의 다른 글
[C#] 실행파일(exe) 이름 가져오기 How to get exe application name (0) | 2021.04.14 |
---|---|
[C#] 디버깅 여부 가져오기 How to detect if debugging (0) | 2021.04.14 |
[C#] DataTable 이행은 이미 다른 테이블에 속해있습니다. (0) | 2018.04.26 |
[C#] DefaultView.ToTable 원하는 컬럼만 복사 또는 지우기 (0) | 2016.06.14 |
[C#] 문자열 뒤집기 Reverse string (1) | 2016.06.02 |