728x90
반응형
728x170
▶ 예제
using System;
using System.Collections.Generic;
#region 도형 출력하기 - PrintShape(shapeList)
/// <summary>
/// 도형 출력하기
/// </summary>
/// <param name="shapeList">도형 리스트</param>
private void PrintShape(List<Shape> shapeList)
{
foreach(Shape shape in shapeList)
{
switch(shape)
{
case null :
Console.WriteLine("NULL");
break;
case Circle circle :
Console.WriteLine($"RADIUS={circle.Radius}");
break;
case Rectangle rectangle when rectangle.Width == rectangle.Height :
Console.WriteLine($"SIZE={rectangle.Width}");
break;
case Rectangle rectangle :
Console.WriteLine($"WIDTH={rectangle.Width},HEIGHT={rectangle.Height}");
break;
default :
Console.WriteLine(shape.ToString());
break;
}
}
}
#endregion
/// <summary>
/// 도형
/// </summary>
public class Shape
{
}
/// <summary>
/// 원
/// </summary>
public class Circle : Shape
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Property
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 반경 - Radius
/// <summary>
/// 반경
/// </summary>
public double Radius { get; set; }
#endregion
}
/// <summary>
/// 사각형
/// </summary>
public class Rectangle : Shape
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Property
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 너비 - Width
/// <summary>
/// 너비
/// </summary>
public double Width { get; set; }
#endregion
#region 높이 - Height
/// <summary>
/// 높이
/// </summary>
public double Height { get; set; }
#endregion
}
728x90
반응형
그리드형(광고전용)
'C# > Common' 카테고리의 다른 글
[C#/COMMON] Version 클래스 : 버전 비교하기 (0) | 2021.02.04 |
---|---|
[C#/COMMON] MSI 파일 설치시 관리자 권한 상승하기 (0) | 2021.02.03 |
[C#/COMMON] 커서 표시하기/숨기기 (0) | 2021.02.02 |
[C#/COMMON] CTRL 키 비활성화/활성화하기 (0) | 2021.02.01 |
[C#/COMMON] 작업 표시줄(Taskbar) 숨기기/보여주기 (0) | 2021.02.01 |
[C#/COMMON] switch문 : 상수 패턴 사용하기 (0) | 2021.01.31 |
[C#/COMMON] is 연산자 : 타입 패턴(Type Pattern) 사용하기 (0) | 2021.01.31 |
[C#/COMMON] is 연산자 : 상수 패턴(Constant Pattern) 사용하기 (0) | 2021.01.31 |
[C#/COMMON] 튜플 분해(Tuple Deconstruction) 사용하기 (0) | 2021.01.30 |
[C#/COMMON] 튜플 리터럴(Tuple Literal) 사용하기 (0) | 2021.01.30 |
댓글을 달아 주세요