본문 바로가기

전체 글

(164)
[2] 자연수의 합 자연수 A,B가 주어지면 A부터 B까지 합을 수식과 함께 출력하세요. 입력설명 첫 줄에 자연수 A,B가 공백을 사이에 두고 차례대로 입력된다. (1> B; for(int i = A; i
[1] 1부터 N까지 M의 배수합 자연수 N이 입력되면 1부터 N까지의 수 중 M의 배수합을 출력하는 프로그램을 작성하세요. 입력설명 첫 줄에 자연수 N과 M이 차례대로 입력됩니다.(3> M; for(int i =1; i
델리게이트와 람다식 using System; class Program { public delegate int Del(int a, int b); static void Main(string[] args) { Del del = (int a, int b) => { return a + b; }; int num = del(1, 1); Console.WriteLine( num ); } } using System; class Program { delegate int Prn1(string s); delegate int Prn2(); delegate void Prn3(string s); delegate void Prn4(); static void Main(string[] args) { Prn1 prn1 = (string s) => { ret..
이벤트 using System; class Button { public delegate void Del(); // 델리게이트 선언 public event Del click; // 이벤트 선언 public void OnClick() // 이벤트 발생 { click(); // 이벤트 통지 } } class MainApp { static void Print() { Console.WriteLine("Click"); } static void Main(string[] args) { Button button = new Button(); button.click += Print; } }
컴포넌트 패턴 컴포넌트 패턴이란 모든 코드를 부품화해서 관리한다. Cube 객체를 유니티에서 생성할 수 있는데 Cube의 컴포넌트를 Copy component를 이용해서 Empty 객체에 복사하게 되면 같은 기능을 가진 객체를 똑같이 만들 수 있다. 유니티에서는 부품을 하나씩 붙여가면서 만드는 방법이 유니티의 중요한 철학이다. Test 스크립트에 Rotate함수에 값을 주고 저장한다. Test스크립트를 생성한 MyCube 객체에 추가하면 회전하는 MyCube객체를 볼 수 있다. using UnityEngine; using System.Collections; public class Test : MonoBehaviour { // Use this for initialization void Start () { } // Upd..
예외처리 try catch when using System; class Program { class FilterableException : Exception { public int ErrorNo { get; set; } } static void Main(string[] args) { Console.WriteLine("Enter Number Between 0~10"); string input = Console.ReadLine(); try { int num = Int32.Parse(input); if (num 10) throw new FilterableException() { ErrorNo = num }; else Console.WriteLine($"Output : {num}"); } catch (FilterableEx..
StringBuilder using System; using System.Text; namespace MyCshap1 { class Program { static void Main(string[] args) { string s = string.Empty; for(int i = 1; i
인덱서 namespace MyCshap1 { class MyArray { private int[] array; public MyArray() { array = new int[5]; } public int this[int index] { get { return array[index]; } set { array[index] = value; } } } class Program { static void Main(string[] args) { MyArray myArray = new MyArray(); myArray[0] = 10; myArray[1] = 20; myArray[2] = 30; myArray[3] = 40; myArray[4] = 50; } } }