==========================================================================================
C#
==========================================================================================
<C#>
==LINQ ( Language INtergrated Query )
=GROUP BY로 데이터 분류
using System; |
=JOIN : 두 데이터 원본 연결
-두 데이터 원본 사이에서 일치하는 데이터들만 연결
-내부 JOIN : 교집합
1.외부조인 : A.Name == B.Star (왼쪽 조인) : 기준이 A => B에 데이터가 없어도 포함됨
: from product in ps.DdfaultEmpty(new Product(){Title="그런거 없음“}
2.내부조인 : join b in B on a.xxxx equals b.yyyy
using System; |
= LINQ의 비밀 / LINQ 표준 연산자
https://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b
using System; |
=
http://www.dotnetperls.com/convert-list-array
==========================================================================================
C++
==========================================================================================
<C++>
=str연산자
(연산자 모음)
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
using namespace std;
class Str
{
friend ostream & operator <<(ostream &c, const Str & S);
friend const Str operator +(const char *ptr, Str &s);
friend bool operator ==(const char *ptr, Str & s);
friend bool operator !=(const char *ptr, Str & s);
friend bool operator >(const char *ptr, Str & s);
friend bool operator <(const char *ptr, Str & s);
friend bool operator >=(const char *ptr, Str & s);
friend bool operator <=(const char *ptr, Str & s);
protected:
char * buf;
int size;
public:
Str();
Str(const char *ptr);
Str(const Str &Other);
explicit Str(int num);
virtual ~Str();
int length() const
{
return strlen(buf);
}
Str &operator =(const Str &Other);
Str &operator +=(Str &Other);
Str &operator +=(const char *ptr);
char &operator [](int idx)
{
return buf[idx];
}
const char &operator[](int idx) const
{
return buf[idx];
}
operator const char *()
{
return (const char *)buf;
}
operator int()
{
return atoi(buf);
}
const Str operator +(Str &Other) const;
const Str operator +(const char *ptr) const
{
//Str t(ptr);
//return *this + t;
return *this + Str(ptr); // 재귀호출 에러
}
bool operator ==(Str &Other)
{
return strcmp(buf, Other.buf) == 0;
}
bool operator ==(const char *ptr)
{
return strcmp(buf, ptr) == 0;
}
bool operator !=(Str &Other)
{
return strcmp(buf, Other.buf) != 0;
}
bool operator !=(const char *ptr)
{
return strcmp(buf, ptr) != 0;
}
bool operator >(Str &Other)
{
return strcmp(buf, Other.buf)>0;
}
bool operator >(const char *ptr)
{
return strcmp(buf, ptr)>0;
}
bool operator <(Str &Other)
{
return strcmp(buf, Other.buf)<0;
}
bool operator <(const char *ptr)
{
return strcmp(buf, ptr)<0;
}
bool operator >=(Str &Other)
{
return strcmp(buf, Other.buf) >= 0;
}
bool operator >=(const char *ptr)
{
return strcmp(buf, ptr) >= 0;
}
bool operator <=(Str &Other)
{
return strcmp(buf, Other.buf) <= 0;
}
bool operator <=(const char *ptr)
{
return strcmp(buf, ptr) <= 0;
}
void Format(const char *fmt, ...);
};
//디폴트 생성자
Str::Str()
{
size = 1;
buf = new char[size];
buf[0] = 0;
}
//문자열로부터 생성하기
Str::Str(const char *ptr)
{
size = strlen(ptr) + 1;
buf = new char[size];
strcpy(buf, ptr);
}
//복사생성자
Str::Str(const Str &Other)
{
size = Other.length() + 1;
buf = new char[size];
strcpy(buf, Other.buf);
}
//정수형 변환 생성자
Str::Str(int num)
{
char temp[128] = { "100" };
//itoa(num, temp, 10);
size = strlen(temp) + 1;
buf = new char[size];
strcpy(buf, temp);
}
//파괴자
Str::~Str()
{
delete[] buf;
}
//대입 연산자
Str &Str::operator =(const Str &Other)
{
if (this != &Other)
{
size = Other.length() + 1;
delete[] buf;
buf = new char[size];
strcpy(buf, Other.buf);
}
return *this;
}
//복합 연결 연산자
Str &Str::operator +=(Str &Other)
{
char * old;
old = buf;
size += Other.length();
buf = new char[size];
strcpy(buf, old);
strcat(buf, Other.buf);
delete[] old;
return *this;
}
Str &Str::operator +=(const char *ptr)
{
//Str t(ptr);
//return *this += t;
return *this += Str(ptr); // 재귀호출 에러
}
//연결 연산자
const Str Str::operator +(Str &Other)const
{
Str T;
delete[] T.buf;
T.size = length() + Other.length() + 1;
T.buf = new char[T.size];
strcpy(T.buf, buf);
strcat(T.buf, (const char *)Other);
return T;
}
//출력 연산자
ostream &operator <<(ostream &c, const Str & S)
{
c << S.buf;
return c;
}
//더하기 및 관계 연산자
const Str operator +(const char *ptr, Str & s)
{
return Str(ptr) + s;
}
bool operator ==(const char *ptr, Str & s)
{
return strcmp(ptr, s.buf) == 0;
}
bool operator !=(const char *ptr, Str & s)
{
return strcmp(ptr, s.buf) != 0;
}
bool operator >(const char *ptr, Str & s)
{
return strcmp(ptr, s.buf) > 0;
}
bool operator <(const char *ptr, Str & s)
{
return strcmp(ptr, s.buf) < 0;
}
bool operator >=(const char *ptr, Str & s)
{
return strcmp(ptr, s.buf) >= 0;
}
bool operator <=(const char *ptr, Str & s)
{
return strcmp(ptr, s.buf) <= 0;
}
//서식 조립 함수
void Str::Format(const char *fmt, ...)
{
char temp[1024];
va_list marker;
va_start(marker, fmt);
vsprintf(temp, fmt, marker);
*this = Str(temp);
}
int main()
{
Str s = "125";
int k;
k = (int)s + 123;
cout << k << endl;
Str s1("문자열"); //문자열로 생성자
Str s2(s1); //복사 생성자
Str s3; //디폴트 생성자
s3 = s1; //대입 연산자
//출력 연산자
cout << "s1=" << s1 << ",s2=" << s2 << ",s3=" << s3 << endl;
cout << "길이=" << s1 << endl;
//정수형 변환 생성자와 변환 연산자
Str s4(1234);
cout << "s4=" << s4 << endl;
int num = int(s4) + 1;
cout << "num=" << num << endl;
//문자열 연결 테스트
Str s5 = "First";
Str s6 = "Second";
cout << s5 + s6 << endl;
cout << s6 + "Third" << endl; // => 실행 에러
cout << "Zero" + s5 << endl;
cout << "s1은 " + s1 + "이고 s5는 " + s5 + "이다." << endl; // => 실행 에러
s5 += s6;
cout << "s5와 s6을 연결하면 " << s5 << "이다." << endl;
s5 += "Concatination"; // => 실행 에러
cout << "s5에 문자열을 덧붙이면 " << s5 << "이다." << endl; // => 실행 에러
//비교연산자테스트
if (s1 == s2)
{
cout << "두 문자열은 같다." << endl;
}
else
{
cout << "두 문자열은 다르다." << endl;
}
//char * 형과의 연산테스트
Str s7;
s7 = "상수 문자열";
cout << s7 << endl;
char str[128];
strcpy(str, s7);
cout << str << endl;
//첨자 연산자 테스트
Str s8("Index");
cout << "s8[2]=" << s8[2] << endl;
s8[2] = 'k';
cout << "s8[2]=" << s8[2] << endl;
//서식 조립 테스트
Str sf;
int i = 9876;
double d = 1.234567;
sf.Format("서식 조립 가능하다. 정수=%d, 실수=%2f", i, d);
cout << sf << endl;
return 0;
}
=결과 error 발생(주석)
==> 에러수정(재귀함수로 무한 반복)
#include <iostream>
|
=
#include <math.h> |
=재정의 가능한 함수
#include <iostream> |
=가상 파괴자
#include <iostream> |
-VERTUAL 추가시 DERROVERD 소멸자 호출 안됨
-VERTUAL 추가시 DERROVERD 소멸자 호출


