Study119 [C#][Study][기초다지기] using 문 using 문 - File이나 Font와 같이 관리되지 않는 클래스, 즉 사용 후 알아서 해제가 되지 않는 자원(리소스)들은 사용자가 직접 해제(Dispose)해 주어야 한다. - 매번 해제해주는 것은 실수가 잦고, 힘들기 때문에 using문을 사용해 자동으로 자원이 해제(Dispose)되게 한다. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Using_Statement { class check_using : IDisposable { public void Dispose() { // 자원이 해제될 때 실행 Console.WriteLine("실행 2"); } } class Progr.. 2023. 9. 23. [C#][Study][기초다지기] lock 문 lock 문 - 현재 thread에서 프로그램을 실행하는동안 다른 thread의 개체를 잠그고, 진행되던 thread의 실행이 끝난 뒤에 개체의 잠금이 해제되어 다음 thread를 실행할 수 있게 함 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Lock_Statement { class Program { public void printname() { Console.WriteLine("My name is Steven Clark"); } static void Main(string[] args) { Program p = new Program(); lock (p) // lock 구문 생성.. 2023. 9. 23. [C#][Study][기초다지기] uncheck 문 uncheck 문 - 스택 오버플로우가 발생해도 예외를 무시하고 실행시킴 - 잘못된 출력이 발생할 가능성이 높음 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Unchecked_Statement { class Program { static void Main(string[] args) { int num = int.MaxValue; // int의 최대값 할당 try { unchecked { // 스택 오버플로우 발생 -> 예외를 처리하지 않고 잘못된 값을 출력함 num = num + 1; Console.WriteLine(num); } } catch (Exception e) { Cons.. 2023. 9. 23. [C#][Study][기초다지기] check 문 check 문 - 오버플로우나 언더플로우시 예외를 발생시킴 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Checked_Statement { class Program { static void Main(string[] args) { int num = int.MaxValue; // int의 최대값 할당 try { checked { // int의 최대값을 넘게하여 스택 오버플로우를 강제로 발생시킴 num = num + 1; Console.WriteLine(num); } } catch (Exception e) { Console.WriteLine(e.ToString()); } Console.. 2023. 9. 23. [C#][Study][기초다지기] throw 문 throw 문 - 예외를 처리할 때 사용 - 예외는 catch 블록에서 처리됨 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace throw_statement { class Program { static void Main(string[] args) { int num1, num2, result; Console.WriteLine("Enter First Number"); num1 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter Second Number"); num2 = Convert.ToInt32(Console.ReadLine.. 2023. 9. 23. [C#][Study][기초다지기] goto 문 goto 문 - label을 선언한 곳으로 돌아감 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace goto_statements { class Program { static void Main(string[] args) { string name; label: // 레이블 생성 -> 콜론 주의! Console.WriteLine("Enter your name: "); name = Console.ReadLine(); Console.WriteLine("Welcome {0}", name); Console.WriteLine("Press Ctrl + C for Exit\n"); goto label;.. 2023. 9. 23. [C#][Study][기초다지기] XOR XOR(^) - 조건이 모두 참 or 모두 거짓 인 경우에만 true 반환 ex) (1 == 0) ^ (1 == 2) => true ex) (1 == 1) ^ (1 == 1) => true ex) (1 == 0) ^ (1 == 1) => false 2023. 9. 23. [C#][Study][기초다지기] C# 사용자 입력 - ReadLine(), Read() Console.ReadLine(), Console.Read() - 사용자 입력을 읽어오는 함수 - 기본 반환형이 string이므로 int형을 반환하려면 형 변환을 해주어야 한다. // 사용자에게 받아온 문자열 입력을 Int형으로 바꾸는 방법 age = Int32.Parse(Console.ReadLine()); // Parse 사용 age = Convert.ToInt32(Console.ReadLine()); // Convert 사용 cf) 출력 함수 = Console.WriteLine("출력 값") 2023. 9. 23. [WPF][MVVM][Study] MVVM 실습 3 - 학생 리스트 만들기 MVVM 패턴을 활용해 WPF로 간단한 학생 리스트를 만들어 보았다. 0. 파일 구조 - 파일의 구조는 아래와 같다. 1. View 생성 [xaml] [code-behind] using System.Windows; namespace WPF_MVVM_EX_App { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); this.DataContext = new ViewModel.StudentViewModel(); } } } - 좌측은 DataGrid를 사용해 학생 목록을 보여주고자 하였고, 좌측에는 선택한 학생의 정보를 보여주고자 하였다. - ViewModel에 DataContext를 연결에 View와 V.. 2023. 9. 22. [WPF][C#][Study] WPF 시작 8일차 1. ItemsControl - Item을 선택할 필요없이 데이터만 보여주기 위한 상황에서 사용하기 좋음 - Item을 선택해야 할 경우에는 ListBox나 ListView를 사용하는 것이 좋음 [예제 1] - 데이터바인딩, 템플릿 사용 - TodoList 1) xmal 2) code-behind using System; using System.Windows; using System.Collections.Generic; namespace WpfTutorialSamples.ItemsControl { public partial class ItemsControlDataBindingSample : Window { public ItemsControlDataBindingSample() { InitializeComp.. 2023. 9. 22. [WPF][MVVM][Study] MVVM 실습 2 - 단위 변환기 2 이번에는 버튼을 눌러야만 단위를 변환해주는 단위 변환기를 만드는 실습을 해보았다. 1 ~ 3. (실습 1)을 참고하여 기본적인 작업을 참고 4. Command 클래스 생성 및 코드 작성 1) Command 클래스를 생성한다.(프로젝트>추가>클래스) 2) 인터페이스 ICommand를 상속받아서 인터페이스를 구현해준다. 3) 생성자를 이용해 외부의 실행 전 조건을 검사할 함수와 실제로 실행할 함수를 저장한다. // Command.cs using System; using System.Windows.Input; namespace WPF_MVVM_EX_2 { class Command : ICommand { Action ExecuteMethod; Func CanexecutedMethod; public Command.. 2023. 9. 21. [WPF][C#][Study] WPF 시작 7일차 1. MessageBox - 메세지 창을 띄운다. - 내용 및 제목, ok, yes, no버튼, 기본 버튼 이미지 등을 기본적으로 추가할 수 있다. [예제] 1) xaml Simple MessageBox MessageBox with title MessageBox with buttons MessageBox with response MessageBox with icon MessageBox with default choice 2) code-behind using System; using System.Windows; namespace WpfTutorialSamples.Dialogs { public partial class MessageBoxSample : Window { public MessageBoxSampl.. 2023. 9. 21. 이전 1 ··· 6 7 8 9 10 다음