전체 글 (104) 썸네일형 리스트형 String to Enum https://magicmon.tistory.com/102 String 문자열을 Enum으로 바꾸는 방법 String 문자열을 Enum으로 바꾸는 방법이다. 만약 다음과 같은 Enum이 있다고 보자 public enum Color { Black, White, Blue, Red, Green } String으로 얻어온 문자를 Enum으로 바꿀려면 다음과 같이 사용하면 된다. Colo magicmon.tistory.com as as 연산자는 C#에서 형변환을 수행하는데 사용됩니다. 이 연산자는 특히 참조형식(Reference Types) 간의 형변환에서 유용하게 사용됩니다. as 연산자는 변환할 수 없는 경우 null을 반환하므로 예외가 발생하지 않습니다. 아래는 as 연산자의 간단한 사용 예제입니다: class Animal { public string Name { get; set; } } class Dog : Animal { public void Bark() { Console.WriteLine("Woof!"); } } class Program { static void Main() { // Dog 객체를 생성 Dog myDog = new Dog(); myDog.Name = "Buddy"; // Animal 형식으로 형변환 시도.. Parallel.ForEach Parallel.ForEach는 Parallel 클래스에서 제공하는 또 다른 기능으로, 컬렉션의 각 요소에 대해 병렬로 작업을 수행합니다. Parallel.ForEach를 사용하면 각 요소에 대한 작업이 병렬로 처리되어 더 효과적인 다중 스레드 활용이 가능합니다. 간단한 사용 예제를 살펴봅시다: using System; using System.Threading.Tasks; class Program { static void Main() { // 병렬로 실행할 컬렉션 var numbers = Enumerable.Range(1, 10); // 병렬로 각 요소에 대한 작업 수행 Parallel.ForEach(numbers, number => { Console.WriteLine($"Task {Task.Curren.. C# 리스트 내의 모든 값이 참이면 조건 실행 using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { List booleanList = new List { true, true, true, true, true }; bool allTrue = booleanList.All(item => item == true); if (allTrue) { Console.WriteLine("리스트 내의 모든 값이 참입니다."); // 여기에서 원하는 작업을 수행할 수 있습니다. } else { Console.WriteLine("리스트 내에 하나 이상의 값이 거짓입니다."); } } } enum 길이 using System; using UnityEngine; enum Item { Gold, Diamond, Ruby } int count = System.Enum.GetValues(typeof(Item)).Length; C# 교육 5일차 WPF xaml 사용자 정의 컨트롤 UserControl Binding code나 tag로 함 source, path 지정해야 함 태그에서 접근 가능 DataContext ↓ ListBox Item -> ToString 보여줌 ToString 재정의 필요 재사용할 것으로 생각되는 것은 Resouce에 정의 ResouceDictionary style trigger 속성 값이 숫자인 속성 설정 가능 Multitask Single Thread Multi-Thread 1. Thread 생성 2. Task MyDelegate d3 = (s) => { Console.WriteLine("Hello," + s); }; //Action 대리자 -반환값이 없는 메서드 호출 :16개 Action a1 = new Action.. C# 교육 4일차 File - static Method 만 제공 File.으로 접근 매 호출 시 security 검사 string filePath = @"C:\fourthCoffee\settings.txt"; string settings = File.ReadAllText(filePath); bool overwrite = true; File.Copy(sourceSettingsPath, destinationSettingsPath, overWrite); FileInfo - new로 접근 객체 생성 시에만 security string filePath = @"C:\fourthCoffee\settings.txt"; FileInfo settings = new FileInfo(filePath); bool overwrite = true;.. C# 교육 3일차 static 메모리에 가장 먼저 잡힘 1. no data, static method만 있는 경우 - 전역함수 대용으로 static Console { public static void WriteLine() { } } 객체가 아무리 많이 생겨도 메모리를 공유한다. 2. static data = data.Length - 1) throw new ArgumentOutOfRangeException("Stack Overflow"); data[++top] = n; } public T Pop() { if(top < 0 ) throw new ArgumentOutOfRangeException("Stack Underflow"); return data[top--]; } } Stack s1 = new Stack(3); s1.Pu.. 이전 1 2 3 4 5 ··· 13 다음