C#(7)
-
[WPF] TreeView SelectedItem Clear
TreeView 구현 코드- xaml에 TreeView와 버튼을 정의. - 버튼 클릭 시 TreeView의 선택을 해제하는 로직.using System.Windows; using System.Windows.Controls; namespace YourNamespace { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void ClearSelection_Click(object sender, RoutedEventArgs e) { ClearTreeViewSelection(MyTreeView); } private void ClearTreeViewSelection(TreeView tree..
2024.05.28 -
[WPF] TextBox 숫자값만 입력받기.
private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e) { if( !((Key.D0
2024.05.17 -
[C#] Stack 사용
using System; using System.Collections.Generic; public class Solution { public void solution() { Stack tmp = new Stack(); //추가 tmp.Push('A'); tmp.Push('B'); tmp.Push('C'); //제거 tmp.Pop();//반환 'C', 상단 원소 제거 tmp.Peek();//반환X, 상단 원소 제거 tmp.Clear();//반환X, 전체 삭제 //IsEmpty if(tmp.Count == 0) return;//비어있음 // 특정 원소 포함 if(tmp.Contains('A')) //'A'포함되어 있는지 파악 //배열 변환 char[] array = tmp.ToArray(); } }
2023.03.26 -
[프로그래머스] 위장
using System; using System.Linq; //Distinct 사용위해 선언 public class Solution { public int solution(string[,] clothes) { int answer = 1; string[] type = new string[clothes.GetLength(0)]; for(int i=0; i
2023.03.23 -
[C#] String 배열 다루기
- 크기 가져오기 1. 일차원 배열 using System; public class Solution{ public int main (){ int[] a = new int[10]; return a.Length; } } 2. 이차원 배열 using System; public class Solution{ public int main (){ int[,] a = new int[10,2]; // 배열 전체 크기 int All = a.Lengh; // 차원의 수 int arrNum = a.Rank;//2 // 각 배열 차원의 크기 int a1_size = a.GetLength(0);//10 int a2_size = a.GetLength(1);//2 return arrNum; } }
2023.03.23 -
string.Equals 사용시 Null 처리
string.Equals 함수 사용하시 값이 null이면 오류가 난다. System.NullReferenceException : 개체 참조가 개체의 인스턴스로 설정되지 않았습니다. Null처리 방법 1. if( !string.IsNullOrEmpty(a) && a.Equals("Y") ) 2. if( "Y".Equals(a) ) 3. if( "Y" == a ) 2번 방법을 사용하면 가독성이 좋으나 NullException 처리는 되지않는다. 이와 관련해서 블로그 글을 참조한다. https://ryusae.tistory.com/m/31 [C#, JAVA] String Equals 비교 시, NULL 체크 간략화 ("Y".Equals() 사용)※ 프로그래밍 작성 스타일에 따른 내용이므로 개인적인 견해가 포함..
2023.03.17