본문 바로가기
728x90
반응형

전체 글303

C#] PeriodicTimer class 몇 시스템 개발 시, task 실행을 일정한 시간을 두고 해야할 때가 있다. C#은 .NET 6에서 소개된 PeriodicTimer class를 제공한다. 기능과 사용법을 살펴보고 간단히 구현해보자. C#에서 PeriodicTimer Class 작동법 1. 필요한 변수를 정의하자. private readonly PeriodicTimer _periodicTimer; private readonly CancellationTokenSource _cancellationToken = new(); private Task? _task; private int _size; 차후 초기화할 PeriodicTimer 변수가 있다. 반복 Task를 종료시킬때 사용할 CancellationTokenSource 변수를 정의하고 초기.. 2024. 1. 9.
C#] Pipes and Filter Architectural Pattern 순차적이고 독립적인 processing data 또는 tasks를 위한 modular 하고 유연한 system을 설계하기 위한 목적의 design pattern이다. 여러 단계를 거치며 각 단계별로 특정한 data 변환 또는 operation이 필요한 data streams을 다루는데 매우 유용하다. data processing pipelinex, text processing와 관련된 application에서 일반적으로 사용되는 패턴이다. 어떻게 이 디자인 패턴이 동작하고 기본적인 개념에 대해 살펴보자. Pipes and Filter Architectural Pattern의 이해 Pipes and Filters pattern은 component-based architectural design patter.. 2024. 1. 9.
C#] Path의 File, Directory 여부 확인 path가 file인지 directory인지 결정하는 방법을 살펴보자. 2가지 방법이 있다. 첫번째는 path가 file 또는 directory로 존재하는지 확인한다. 두번째는 path의 attribute를 확인한다. Directory, File 존재여부 확인 .NET에는 2쌍의 클래스가 있다. File과 Directory가 있고, FileInfo와 DirectoryInfo가 있다. File 함수는 FileInfo 함수와 비슷하고, Directory함수는 DirectoryInfo 함수와 비슷하다. Directory에서 file을 구분하는데 이 클래스들이 어떻게 사용되는지 보자. Directory와 File 클래스의 사용 File와 Directory는 static class이다. 둘다 Exists() 함수.. 2024. 1. 5.
C#] System.Linq.Enumerable.Aggregate 함수 MS 문서를 기반으로 단계별로 살펴보자. Aggregate() 함수는 source 순서로 모든 elements에 function을 적용하고, 매 함수 호출의 결과값으로 누적된 값을 계산한다. 3개의 오버로드를 갖는다. 1. Aggregate(IEnumerable, Func) public static TSource Aggregate (this System.Collections.Generic.IEnumerable source, Func func); Code Example string sentence = "the quick brown fox"; // 위 문자열을 개별 단어로 나눈다. string[] words = sentence.Split(' '); string reversed = words.Aggregate.. 2023. 11. 15.
C#] LINQ - Any(), Exists() 함수 차이 출처 : Differences Between Any and Exists Methods in C# - Code Maze (code-maze.com) 두 함수는 비슷해보이지만, 각자 고유의 특성이 있다. Any Method LINQ Any() 함수는 collection의 어떤 element가 주어진 조건을 만족하거나 존재하는지 결정하도록 한다. collection의 elements를 하나하나씩 확인하며, result가 결정될 때마다 boolean value를 반환한다. IEnumerable interface를 구현하는 모든 collections(Arrays, Lists, Dictionaries)와 함께 사용할 수 있다. collections이 null이면 ArgumentNullException 에러를 던진다.. 2023. 11. 15.
C#] Discard Variable '_' 사용법 출처 : Using a Discard Variable in C# - Code Maze (code-maze.com) discard variable과 usuable variable의 차이를 알아보고, 실사용법도 살펴보자. C# 7은 코드에서 불필요한 값을 대체할 discards를 소개했다. write-only variable이며, compiler나 코드를 읽는 사람이 누구든 diacard variable의 content를 버려도 됨을 나타낸다. 값을 받지만, 사용할 일이 없는 경우에 유용하다. Usual Variable과 Discard Variable의 차이점 discard는 '_' 문자로 표기한다. _ = "This is the syntax for a discard"; discards는 할당되지 않은 변수.. 2023. 11. 14.
728x90
반응형