728x90
반응형
728x170
▶ School.cs
using System;
namespace TestProject
{
/// <summary>
/// 학교
/// </summary>
public class School : ICloneable
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Property
////////////////////////////////////////////////////////////////////////////////////////// Public
#region ID - ID
/// <summary>
/// ID
/// </summary>
public int ID { get; set; }
#endregion
#region 명칭 - Name
/// <summary>
/// 명칭
/// </summary>
public string Name { get; set; }
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 객체 SHALLOW 복사하기 - ShallowCopy()
/// <summary>
/// 객체 SHALLOW 복사하기
/// </summary>
/// <returns>복사 객체</returns>
public School ShallowCopy()
{
return (School)MemberwiseClone();
}
#endregion
#region 복제하기 - Clone()
/// <summary>
/// 복제하기
/// </summary>
/// <returns>복제 객체</returns>
public School Clone()
{
return DeepCopy();
}
#endregion
#region 복제하기 - ICloneable.Clone()
/// <summary>
/// 복제하기
/// </summary>
/// <returns>복제 객체</returns>
object ICloneable.Clone()
{
return Clone();
}
#endregion
////////////////////////////////////////////////////////////////////////////////////////// Protected
#region 객체 DEEP 복사하기 - DeepCopy()
/// <summary>
/// 객체 DEEP 복사하기
/// </summary>
/// <returns>복사 객체</returns>
protected virtual School DeepCopy()
{
School school = new School();
school.ID = ID;
school.Name = string.Copy(Name);
return school;
}
#endregion
}
}
728x90
▶ Student.cs
using System;
namespace TestProject
{
/// <summary>
/// 학생
/// </summary>
public class Student : ICloneable
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Property
////////////////////////////////////////////////////////////////////////////////////////// Public
#region ID - ID
/// <summary>
/// ID
/// </summary>
public int ID { get; set; }
#endregion
#region 명칭 - Name
/// <summary>
/// 명칭
/// </summary>
public string Name { get; set; }
#endregion
#region 학교 - School
/// <summary>
/// 학교
/// </summary>
public School School { get; set; }
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 객체 SHALLOW 복사하기 - ShallowCopy()
/// <summary>
/// 객체 SHALLOW 복사하기
/// </summary>
/// <returns>복사 객체</returns>
public Student ShallowCopy()
{
return (Student)MemberwiseClone();
}
#endregion
#region 복제하기 - Clone()
/// <summary>
/// 복제하기
/// </summary>
/// <returns>복제 객체</returns>
public Student Clone()
{
return DeepCopy();
}
#endregion
#region 복제하기 - ICloneable.Clone()
/// <summary>
/// 복제하기
/// </summary>
/// <returns>복제 객체</returns>
object ICloneable.Clone()
{
return Clone();
}
#endregion
////////////////////////////////////////////////////////////////////////////////////////// Protected
#region 객체 DEEP 복사하기 - DeepCopy()
/// <summary>
/// 객체 DEEP 복사하기
/// </summary>
/// <returns>복사 객체</returns>
protected virtual Student DeepCopy()
{
Student student = new Student();
student.ID = ID;
student.Name = string.Copy(Name);
student.School = School.Clone();
return student;
}
#endregion
}
}
300x250
▶ Program.cs
using System;
namespace TestProject
{
/// <summary>
/// 프로그램
/// </summary>
class Program
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Private
#region 프로그램 실행하기 - Main()
/// <summary>
/// 프로그램 실행하기
/// </summary>
private static void Main()
{
School school1 = new School();
school1.ID = 1;
school1.Name = "동북고";
Student student1 = new Student();
student1.ID = 1;
student1.Name = "홍길동";
student1.School = school1;
Student student2 = student1.Clone();
Console.WriteLine(student1.School == student2.School);
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > Common' 카테고리의 다른 글
[C#/COMMON] 단일 프로세스 여부 구하기 (0) | 2020.02.02 |
---|---|
[C#/COMMON] 개발 프로세스 여부 구하기 (0) | 2020.02.02 |
[C#/COMMON] 64비트 프로세스 여부 구하기 (0) | 2020.02.02 |
[C#/COMMON/.NETCORE] switch 명령문 : 튜플 패턴(Tuple Pattern)에서 when 키워드 사용하기 (0) | 2020.02.01 |
[C#/COMMON/.NETCORE] switch문 : 튜플 패턴(Tuple Pattern) 사용하기 (0) | 2020.02.01 |
[C#/COMMON/.NET6] Array 클래스 : Copy 정적 메소드를 사용해 바이트 배열 병합하기 (0) | 2020.01.12 |
[C#/COMMON] 한글 문자를 초성/중성/종성으로 분리하기 (0) | 2020.01.12 |
[C#/COMMON] CultureInfo 클래스 : yyyy-MM-dd HH:mm:ss 포맷 문자열 전역 설정하기 (0) | 2019.12.26 |
[C#/COMMON] MeasureIt (0) | 2019.11.29 |
[C#/COMMON] CLR Profiler for .NET Framework 4 (0) | 2019.11.29 |
댓글을 달아 주세요