C#8 C# Throw 발생 방법 C#에서 throw 키워드는 예외(Exception)를 발생시키는 데 사용됩니다. 특정 조건이 만족되지 않을 경우 예외를 던져 프로그램이 예외 처리 로직을 수행하도록 할 수 있습니다. 1. 기본적인 throw 사용 방법throw new Exception("에러가 발생했습니다!"); 2. 조건부 예외 발생 특정 조건을 검사하고, 필요할 때만 예외를 발생시키는 방법입니다.void ValidateAge(int age){ if (age 📌 throw new ArgumentException("메시지")를 사용하여 잘못된 인수에 대한 예외를 던질 수 있습니다. 3. 사용자 정의 예외 클래스 C#에서는 표준 예외 유형 외에도 사용자 정의 예외를 만들 수 있습니다.public class CustomExcepti.. 2025. 5. 13. C# 폴더 내부 파일을 다른 폴더로 복사 C#에서 특정 폴더 내부의 파일을 다른 폴더로 복사하려면 System.IO 네임스페이스의 Directory 및 File 클래스를 사용할 수 있습니다. 다음은 폴더 내의 모든 파일을 복사하는 방법입니다. 1. 파일만 복사 (Directory.GetFiles 사용)using System;using System.IO;class Program{ static void Main() { string sourceFolder = @"C:\SourceFolder"; string destinationFolder = @"C:\DestinationFolder"; // 대상 폴더가 없으면 생성 if (!Directory.Exists(destinationFolder)) .. 2025. 5. 13. C# Random 함수 사용 C#에서는 rand()라는 함수가 따로 존재하지 않지만, 난수를 생성할 때는 System.Random 클래스를 사용합니다. 1. 기본적인 난수 생성Random rand = new Random();int randomNumber = rand.Next(); // 0 이상 int.MaxValue 미만의 랜덤 숫자 생성Console.WriteLine(randomNumber); 💡 rand.Next()는 int 범위 내에서 난수를 생성합니다. 2. 특정 범위의 난수 생성 만약 1부터 100 사이의 난수를 생성하려면 다음과 같이 사용할 수 있습니다:int randomNumber = rand.Next(1, 101); // 1 이상 100 이하의 난수 생성Console.WriteLine(randomNumber); 💡.. 2025. 5. 13. C# 선택한 폴더 안의 파일 및 폴더 삭제 방법 1. 선택한 폴더 안의 파일을 검색해서 삭제 후 폴더 삭제 방법using System;using System.IO;class Program{ static void Main() { string targetFolder = @"C:\ExampleFolder"; if (Directory.Exists(targetFolder)) { // 폴더 내 파일 삭제 foreach (string file in Directory.GetFiles(targetFolder)) { File.Delete(file); Console.WriteLine($"파일 삭제됨: {file}.. 2025. 5. 13. Team Foundation Server 버전 제어" 경고 메시지 제거 방법 MSVS 프록젝트 실행할 때 "Team Foundation Server 버전 제어" 경고 메시지 제거 방법 Team Foundation Server 버전 제어 열려는 솔루션은 Azure DevOps Server http://192.168.11.40:8080/tfs/general%20applications의 소스 제어에 바인딩되어 있습니다. 이 서버에 연결하여 소스 제어 통합을 사용하도록 설정하시겠습니까? 위와 같이 경고 메시지가 표시되는 프로젝트가 존재한다. Team Foundation Server를 설정한 프로젝트인데 나는 SVN을 사용하기 때문에 이 경고 메시지를 삭제하고 싶다. 이때 Solution 파일을 열어 보면 아래와 같은 Tag가 존재하다. GlobalSection(TeamFoundation.. 2023. 4. 20. C# split 사용 방법 https://learn.microsoft.com/ko-kr/dotnet/csharp/how-to/parse-strings-using-split String.Split을 사용하여 문자열 나누기(C# 가이드) Split 메서드는 구분 기호 세트에서 분리된 문자열 배열을 반환합니다. 문자열에서 부분 문자열을 추출하는 간편한 방법입니다. learn.microsoft.com char[] delimiterChars = { ' ', ',', '.', ':', '\t' }; string text = "one\ttwo three:four,five six seven"; System.Console.WriteLine($"Original text: '{text}'"); string[] words = text.Split(del.. 2023. 1. 19. Telerik RadGrid Refresh, 동적으로 Binding data 변경 후 GridView Refresh Telerik의 RadGridView를 사용하고 있는데 DataSource로 바인딩한 정보를 동적으로 변경하면 화면에 바로 업데이트 되지 않는다. 가장 기본적인 방법은 DataSource = null로 초기화를 하고 다시 바인딩을 하는 것이다. 이렇게 하면 당연히 동적으로 변경된 데이터가 화면에 보일 것이다. 하지만 이렇게 하면 화면이 깜박거리거나 데이터가 많으면 표시되는 속도가 느린 문제가 있다. WPF나 Winform 모두 처리하는 방법은 같다. 검색을 해보니 아래와 같은 정보를 찾을 수 있었다. https://docs.telerik.com/devtools/winforms/controls/gridview/populating-with-data/reflecting-custom-object-changes-.. 2022. 6. 3. convert time_t to System.Datetime and TimeZoneInfo C#에서 time_t 값을 System.Datetime으로 변경하는 방법과 UTC --> Local Time 변경 방법 time_t ttime; System.DateTime timeUtc = new System.DateTime(1970, 1, 1).AddSeconds(ttime); TimeZoneInfo cstZone = TimeZoneInfo.FindSystemTimeZoneById("Korea Standard Time"); DateTime cstTime = TimeZoneInfo.ConvertTimeFromUtc(timeUtc, cstZone); time_t는 1970년 1월 1일 기준으로 지난 초를 표시한다. 따라서 System.DateTime의 AddSeconds 함수를 이용해서 컨버를 한다. U.. 2020. 10. 14. 이전 1 다음